Topic: foldl javascript prototype question

Hey all,

I found someone using an example of a script here. I don't understand it. Where is "acc" being defined?

Array.prototype.foldl = function(fnc,start) {
    var a = start;
    for (var i = 0; i < this.length; i++) {
        a = fnc(this,a);
    }
    return a;
}

Some trivial examples could be:

var l = ["hello" , "world"];
l.foldl(function(i, acc) { return acc+" "+i; }, "") // => returns "hello world"

Last edited by johnmerlino (2010-06-13 16:56:12)