Alternative to Function.bind

Igor Bukanov igor at mir2.org
Sun Mar 22 20:11:51 PDT 2009


Various current proposals for Function.bind have a drawback that in a
typical situation one needs to use the reference to the object twice
as in

  obj.method.bind(obj)

This double-referencing can be avoided if bind would be applied to the
object, not to the function. The result of the bind call would be a
view of the object that translates any function property of the object
into a bound function so obj.method.bind(obj) could be written as

  obj.bind().method

Even shorter form can be archived if bind would not be a function but
rather a getter-property so the above can be written as

  obj.bind.method

With such short form the need, for example, for Array methods taking
an extra thisObj argument would be pretty much removed.

Igor


More information about the Es-discuss mailing list