R
RubyRedRick
I bought Crockford's "JavaScript: The Good Parts" yesterday to help
build my JavaScript foo.
On page 44, he gives an implementation of the curry function:
Function.method('curry', function() {
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function() {
return that.apply(null, args.concat(slice.apply(arguments)));
};
});
I'm trying to reconcile the two invocations of slice.apply(arguments)
with the notion that the slice method in Array's prototype has two
arguments, the second of which is optional.
I thought that this would mean that those invocations would need to be
slice.apply(arguments,0) in order to supply the start argument, and in
"leap before you look" mode I submitted an erratum to O'Reilly.
Now however, I've actually tried the code in both Firefox and Safari,
and it seems to work as it's given in the book.
So is the first argument to slice really optional despite the various
doc's I've checked (including and besides the book in question), or
are Firefox and Safari both working outside of the JS spec here, or is
there something else I'm missing?
build my JavaScript foo.
On page 44, he gives an implementation of the curry function:
Function.method('curry', function() {
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function() {
return that.apply(null, args.concat(slice.apply(arguments)));
};
});
I'm trying to reconcile the two invocations of slice.apply(arguments)
with the notion that the slice method in Array's prototype has two
arguments, the second of which is optional.
I thought that this would mean that those invocations would need to be
slice.apply(arguments,0) in order to supply the start argument, and in
"leap before you look" mode I submitted an erratum to O'Reilly.
Now however, I've actually tried the code in both Firefox and Safari,
and it seems to work as it's given in the book.
So is the first argument to slice really optional despite the various
doc's I've checked (including and besides the book in question), or
are Firefox and Safari both working outside of the JS spec here, or is
there something else I'm missing?