lorlarz said:
lorlarz wrote
In the code sample below, how are arguments a legitimate
argument to Array.slice?
[snip]
This code is from a draft of a new JavaScript book
by a major expert.
LOL. I think I know whose book this is.
He is grabbing
the arguments property of the function and passing
it as an argument to Array.prototype.slice
Is he using his sword?
The contents of the arguments property that the function
receives is just the object myObject, so there seems to be
nothing to slice.
I think I see Lasse is helping you just a little too much. I've
mentioned the EcmaScript specification to you before. Do a little
research there first. You can search that specification for "call(" .
Then search for "slice(" and see what that does.
You can find the "unofficial edition" spec in HTML on bclary.com and the
official version in pdf here:
http://www.ecma-international.org/publications/standards/Ecma-262.htm
Garrett
I really do not consider you to have a legitimate criticism
of me asking the question. IF THIS rather hard-to-understand
routine is not something one can ask about here, WHAT IS??
One can _always_ find _all_ the answers elsewhere (FACT), but
can sometimes learn more more clearly from some of the better
people HERE. And, that is what the group is about. (Otherwise,
if someone can always find the answer elsewhere & in _your view_
should not ask the question here, NO QUESTIONS would be
"legitimate" here!!!! Isn't this silly???)
Now, how is this particular thing is harder than just call and
slice? Well, first you must know that arguments is an object
and that an object is seen as a single entity. Then you must
realize that the first argument to call simply sets the
context of "this" plus that slice is just being using to make
this object a one element array. This is not something all
readily understand.
Truth is I have a remaining question . It is that in
the code,
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)));
,
it seems apply (there) is potentially getting an extra,
array element (because the first element in arguments
is still the object (the one setting the context of "this).
Thus, I am not sure I still fully understand and
am trying not to be embarrassed asking the question
HERE, despite criticism of asking the question I
aready have.
So, Lasse, I am still listening.