Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at
Fri Jan 6 09:27:53 PST 2012

that whole variable can be redefined or used as communication channel ... I
really don't understand what is the problem.

The returned bound once object could be frozen without problems but if the
function is private with the gist I have posted:

 1. you cannot redefine Object.prototype at all
 2. you cannot access single bound function/object from any other place

If I have my own scope I want to do what's needed, this does not mean the
problem does not exist, isn't it?

In your case you have, as example, different problems with that WeakMap

 1. everyone can WeakMap = function () {}; anywhere
 2. if already defined, the definition of Object getOwnPropertyDescriptor
to avoid access to that "protected" variable will fail and throw an error
... isn't it? That does not look safe either
 3. as you wrote, Proxy easily discover that secret
 4. your implementation has same problem I am talking about ... trapped
"protected/private" stuff others should not see

Same stuff with my problem except even proxy won't be able to retrieve that
bound function since no property is attached.

I can't hardly believe you are so worried about an edge case and you don't
see the pachyderm we are all dealing with ... properties attached and
accessible "from everyone" ... this is for you safe?

Is obj.bound = obj.method.bind(obj) a better approach than the one I am
suggesting ?

I am sorry but I don't think so.

Best Regards

On Fri, Jan 6, 2012 at 6:03 PM, Mark S. Miller <erights at> wrote:

> On Fri, Jan 6, 2012 at 1:50 AM, David Bruant <bruant.d at> wrote:
>>  Le 06/01/2012 10:40, Andrea Giammarchi a écrit :
>> if WeakMaps are so smart ... it means we cannot shim them without causing
>> leaks in non WeakMap ready browsers since no magic will happen,objects as
>> keys will simply be persistent in the WeakMap private scope
>> Indeed. Also, Mark Miller mentionned a couple of times that the SES
>> polyfill [1] leaks less than one could expect. I haven't taken the time to
>> look into that but it's probably worth mentionning.
> And it's probably worth looking into ;)
>>  [1]
> --
>     Cheers,
>     --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list