Most libraries with enumerator methods (even native JavaScript, I think) allow the passing of a context
for the iterator.
function reduce(iterator, memo, context){
this.each(function(item, idx, list){
memo = iterator.call(context, memo, item, idx, list)
});
return memo;
}
The question is why when bind
can easily offer the same feature?
stooges.reduce(function(memo, stooge){
...
}, context) // as argument vs...
stooges.reduce(function(memo, stooge){
...
}.bind(context))
Is this something that exists for the time being since bind
is not readily available on all platforms? Or is it simply because there is less overhead to call
ing than bind
ing? I always read that the fewer arguments a function takes the better. That is a function taking 0 args is better than one taking 1 is better than one taking 2, etc.