Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Function composition in JS

Name: Anonymous 2012-09-27 1:26

Is there a smarter/better way to write this?


function c() {
    var fs = arguments;
    return function(x) {
        return Array.prototype.reduceRight.call(fs, function(x, f) {
            return f(x);
        }, x);
    }
}

Name: Anonymous 2012-09-27 2:15

>>2
I was kind of annoyed that all that line noise was necessary just to use reduceRight. One consequence of OOP is that functions are imprisoned inside classes but at least javascript provides .call to let you freely pass in "this" of your choice.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List