Improving Function.prototype.bind

Mark S. Miller erights at google.com
Fri Jan 6 09:04:24 PST 2012


Yes. Under SES, Object is shared by Alice and Bob (and Carol). But it is
not a communications channel since it (and all its methods, etc) are all
frozen.

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

>   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 <erights at google.com>
> *Sent:* Friday, January 06, 2012 5:53 PM
> *To:* François REMY <fremycompany_pub at yahoo.fr>
> *Cc:* Brendan Eich <brendan at mozilla.com> ; Andrea Giammarchi<andrea.giammarchi at gmail.com>;
> es-discuss <es-discuss at mozilla.org>
> *Subject:* Re: Improving Function.prototype.bind
>  On Fri, Jan 6, 2012 at 1: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?
>>
>
> No, for the same reason. The mutable state you hung off this internal
> property creates an ambient communications channel.
>
>
>>
>> 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
>> ______________________________**_________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120106/2789bf1c/attachment.html>


More information about the es-discuss mailing list