2010/12/31 Joe <[email protected]>:
> I'm running through John Resig's "Learning Advanced JavaScript" and I
> ran into some questions when I got to slide #45 (http://ejohn.org/apps/
> learn/#45).
> In the example, an arguments collection is passed to a function which
> is supposed to return a true array of the contents of arguments. I
> figured the function would look something like this:
>
> function makeArray(array){
> return Array.slice.call(array, 0);
> }
Since the Array function doesn't have a slice method, you could use
function makeArray(array){
return Array.prototype.slice.call(array, 0);
}
>
> But this failed to work, and Resig's function, which worked, looked
> like this:
>
> function makeArray(array){
> return Array().slice.call( array );
> }
The Array() creates a new empty Array, that also has a slice method,
but does another call, so it is not that elegant nor as fast as using
the prototype's function.
--
Poetro
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]