Improving Function.prototype.bind

François REMY fremycompany_pub at
Fri Jan 6 09:02:18 PST 2012

Sorry, I don’t understand how. [[boundFunctions]] is not readable from the script itself, only from the UA.

To retreive an element from [[boundFunctions]] you need the original function used to create it. If you’ve recieved an instance to that function, you already have a communication channel, right? Or am I missing something?

From: Mark S. Miller 
Sent: Friday, January 06, 2012 5:53 PM
To: François REMY 
Cc: Brendan Eich ; Andrea Giammarchi ; es-discuss 
Subject: Re: Improving Function.prototype.bind
On Fri, Jan 6, 2012 at 1:29 AM, François REMY <fremycompany_pub at> 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?

No, for the same reason. The mutable state you hung off this internal property creates an ambient communications channel.


  -----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.

  es-discuss mailing list
  es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list