I'm trying some basic FP techniques in JavaScript. The compose function takes two functions and give out their Composition function. Now I want to make compose a part of the Function such that I can chain it with ease.
var compose = (func1, func2) => (args => func2(func1(args)));
var square = x => x * x;
var cube = x => x * x * x;
var sixthPower = compose(cube, square);
console.log(sixthPower(2)); // 64
console.log(compose(cube, x => x)(3)); // 27
Function.prototype.compose = function(func) {
return function(args) {
func(/* not sure what to write here */)
}
}
// to make this possible
console.log(square.compose(cube)(3));