An Introduction to Functional JavaScript |

M. David Green demonstrates how you can start thinking functionally in JavaScript, by refactoring some all-too-common imperative code to a functional style.

Source: An Introduction to Functional JavaScript

The article starts with an old classical way of doing things with JavaScript and the DOM. Things like global variables with generic names!

It is then translated to a more modern OOP that uses the IIFE, the strict directive, constructor function and its prototype.

And then we enter the world of functional JavaScript! I can’t remember well right now but the final solution reminds me of a design pattern.

One additional interesting thing in the examples is how the author uses string concatenation through arrays ([].join()) instead of “str1” + “str2” as this way is proved to be faster probably because the + operator is overloaded to work with multiple variable types or something else – just remember that string concatenation in JavaScript is slow.

There’s one other solution to the same problem in the comments which may be called one-liner and also the type of Clever Programming which happens when the code is short, fast and clever but a bit hard for beginners to read and understand fast. However using regex is a must for experienced developers which makes this solution also good.

Keep reading on the link above.

Your first app: node.js by Jim Schubert

I started reading the book "Your first app: node.js" by Jim Schubert. It has a good ...

Learn more
Tagged , . Bookmark the permalink.

About Iliyan Trifonov

Web Developer, Blogger