Here's one of the examples that was sticking out in my mind earlier that
Brendan's solution takes care of. Array.prototype.reduce requires that if
the initial value isn't provided then the first value of the array is the
initial value.
Using rest:
function reduce(callback, ...initial){
var current, index;
if (initial.length) {
index = 0;
current = initial[0];
} else {
index = 1;
current = this[0];
}
...etc...
}
Using arguments.length:
function reduce(callback, initial){
var current, index;
if (arguments.length > 1) {
index = 0;
current = initial;
} else {
index = 1;
current = this[0];
}
...etc...
}
I guess using rest like that is not a bad way to solve it, though it's not
saying what you mean but rather kind of hacking around the limitation.
Either way, it's certainly possible to forgo using arguments to accomplish
the goal.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss