Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Jan 6 01:42:16 PST 2012


that's pretty much what I have already written in my blog ... isn't it?

The speed up is that "ghost" list of bound functions per object hard to
properly manage, performances speaking, via pure JS

It seems that at least you perfectly got what I am talking about, yeah :D

br

On Fri, Jan 6, 2012 at 10:29 AM, François REMY <fremycompany_pub at yahoo.fr>wrote:

> Such an implementation would be very slow and not efficient, because
> searching for a key in the "boundFunctions" weakmap would take time. It can
> be a polyfill solution but a new implementation need something better.
>
> I think the solution would be to create an "invisible" [[boundFunctions]]
> property for all objects containing a dictionnary<weak<function>,
> weak<boundFunction>> of already-bound functions on the object. The
> implementation of bind would then be :
>
> - if objToBind is not a reference, create a new boundFunction and return
> it.
> - if objToBind.[[boundFunctions]] don't exist, create it.
> - else, check if it contains a key for functionToBind //when you are
> processing the dictionnary, remove obsolete entries you may find
>   - if yes, check if the weak reference is alive
>   - if yes, returns the boundFunction
> - create a new boundFunction and store it into objToBind.[[boundFunctions]]
> - return the newly created boundFunction
>
> Would that be possible?
>
> François
>
>
>
> -----Message d'origine----- From: Brendan Eich
> Sent: Friday, January 06, 2012 2:22 AM
> To: Andrea Giammarchi
> Cc: Axel Rauschmayer ; François REMY ; es-discuss
> Subject: Re: Improving Function.prototype.bind
>
> On Jan 5, 2012, at 4:47 PM, Andrea Giammarchi wrote:
>
>  Guys, by any chance we can go back into the topic?
>>
>
> You'll have to polyfill Function.prototype.bind in the current world of
> pre-ES5 browsers. Why not then go on to wrap it in a memoizing version that
> uses a WeakMap if available (emulated with strong keys/values array-based
> implementation if not)?
>
> If you need this machinery, it's all doable. If we should evolve a Harmony
> bind or betterBind based on your experience and others, we can do that.
>
> Right now the lack of memoization is not a burning issue, from what I
> hear. You've raised it, I think for the first time on es-discuss.
>
> /be
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120106/1929db81/attachment.html>


More information about the es-discuss mailing list