Function.prototype.bind behaviour (call vs apply)

Jordan Osete jor at joozt.net
Thu Aug 20 23:45:55 PDT 2009


Hello everybody.

The currently proposed bind() method for function objects behaves like
call(): it takes a number of arguments (from arguments[1] 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 ?

Regards,

Jordan OSETE






More information about the es-discuss mailing list