Function.prototype.bind behaviour (call vs apply)
jor at joozt.net
Thu Aug 20 13:33:00 PDT 2009
The currently proposed bind() method for function objects behaves like
call(): it takes a number of arguments (from arguments onwards), and
uses them for the function execution.
Wouldn't it be more flexible to behave like apply(), taking an array of
parameters instead of taking each parameter individually ?
The second approach seems more powerful to me. That is, every call() can
easyly be replaced by apply():
func.call( thisObj, a, b, c ) -> func.apply( thisObj, [ a, b, c ] )
...But when you only have got an array of arguments, you can't go the
other way around:
func.apply( thisObj, argsArray ) -> func.call( /* impossible */ )
Would it be possible to change bind to behave like apply ?
More information about the es-discuss