  | |  | SV: [Flashcoders] Why apply | SV: [Flashcoders] Why apply
2004-02-18 - By Martin Klasson
Back
Thankyou both Darron and Jesse.
Perfect explaination.
Seems the apply can be useful, though call will be less useful
Thanks
/ mk
-- --Ursprungligt meddelande-- --
Från: Darron J. Schall [mailto:darron@(protected)]
Skickat: den 18 februari 2004 16:12
Till: flashcoders@(protected)
Ämne: Re: [Flashcoders] Why apply
They 're not quite the same. Arguments is an array containing the parameters
passed in.
When you call this.init(arguments), you 're not directly passing the
arguments from the function to init -- you 're actually passing an array of
the arguments to the init function. This doesn 't work because your init
function is expecting a regular parameter list (param1, param2, etc).
By using apply, the first parameter is the scope (object to apply the
function to), and the second parameter is an array of arguments. Because
the second param is an array of arguments, using the arguments keyword is a
great application. You init function will get the parameter list it 's
looking for.
So, we take the init function and apply it to this (the current instance),
passing in all of the arguments that were passed in to the function calling
init (which, in your example, is the constructor for the Parent class).
On a related note, Function.call is similar to apply (allows you to specify
a new scope for the function), but it takes the parameters as a regular
parameter list, not as an array..
this.init.call(this, param1, param2, etc);
would be the same as
this.init(param1, param2, etc);
-d
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104605
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104614
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |