“Function Composition” sounds complicated, what is it?
It’s actually simple to explain and hopefully understand. (Multiple) function composition is the generation of a high-order function by combining simpler functions. It’s probably easier explained using an example.
Basic example using functional.js to combine two functions
As you can see, the output from the right-most function is passed as the argument to the next function on the left, you’re then returned “hello 2” as a single result. Thanks to @ryansroberts for this one.
Example using functional.js to combine three functions
This example illustrates the combining of multiple functions, passing the output from function “g” as a parameter to function “f”, then passing the output from function “f” as a parameter to function “e”. This leaves you with a single returned result, in this case “hello 201”.
Haha, no :) it’s not a function inheriting properties from another function, it’s a function composed of other functions. I suggest you look up prototypal inheritance. Sometimes it’s ok to link to Crockford.
What’s the benefit?
It’s coming on, and expect more function-level programming support soon. Don’t be shy to contribute and note that I’m currently using 4 soft spaces for tabs, don’t make me go all Crockford on you.