Alternative to Function.bind

Brendan Eich brendan at
Fri Mar 27 10:35:06 PDT 2009

On Mar 22, 2009, at 8:11 PM, Igor Bukanov wrote:

> 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 is common, but not majority-case from a quick survey:

$ find MochiKit -name '*.js' -print |  
xargs fgrep .bind\( | wc -l
$ find MochiKit -name '*.js' -print |  
xargs fgrep .bind\( | /tmp/ | wc -l

where looks for /\b(\w+)\.\w+\.bind\(\1[,)]/  

Anyway, bind is being standardized based on the de-facto standard, the  
common intersection semantics among popular Ajax libraries' bind-like  
methods (jQuery has a different bind so I left it out of my find above).

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

This is cool, although perhaps the name should be something else:


or just


Don't want to get all long-winded, but do want to avoid overloading  
the ever-popular "bind".


More information about the Es-discuss mailing list