bruant.d at gmail.com
Thu Jan 5 14:01:34 PST 2012
It seems that what you want can be implemented as a library 
(actually you did it as well in your blog post). In this gist, a cache
is used. In a nutshell, it is a '(function, object) -> boundFunction'
mapping. I used 2 levels of WeakMaps to achieve this.
I don't think a native implementation could be that much more efficient
neither in space nor time.
Assuming my implementation does what you need, what would be the benefit
of a native implementation over what I propose?
Le 05/01/2012 14:54, Andrea Giammarchi a écrit :
> 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)
> or, if you prefer
> === sameObject.asContextOf(genericCallback)
> Here the whole post with better examples plus the proposed solution
> that would be nice to have in JS.Next
> Best Regards,
> Andrea Giammarchi
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss