Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Jan 5 05:54:11 PST 2012


I have thought it may be interesting to receive some comment here too ...
so here the short summary:

genericCallback.bind(sameObject) !== genericCallback.bind(sameObject)

quite inconvenient for listeners and leading to uncomfortable patterns (
store the bound reference somewhere and get it back later )

plus bind, at the end of a function, where the topic is the context, looks
more like a yoda statement

"function with context as this object"

rather than

"object as context of this function"

So, the proposal, is a simplified Object.prototype.boundTo ( or eventually,
to avoid conflicts with bind signature Object.prototype.asContextOf )
where the action is object, as context, related, and the returned function
is one and one only

sameObject.boundTo(genericCallback) === sameObject.boundTo(genericCallback)

or, if you prefer

sameObject.asContextOf(genericCallback) === sameObject.asContextOf(
genericCallback)

Here the whole post with better examples plus the proposed solution that
would be nice to have in JS.Next
http://webreflection.blogspot.com/2012/01/improving-functionprototypebind.html

Best Regards,
    Andrea Giammarchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120105/f8f0f890/attachment.html>


More information about the es-discuss mailing list