Improving Function.prototype.bind

Axel Rauschmayer axel at
Thu Jan 5 16:32:51 PST 2012

> I do not believe (Axel) that the spec's Reference internal type is helpful as an externally-visible part of the language in any of this.

I believe you, I know nothing about how references are actually implemented. Python works like this:

    class Foo:
        def bar():

    $ f = Foo()
    <bound method of <__main__.Foo instance at 0x103e57950>>

It has always surprised me that JavaScript preserved `this` here:
    (new Date().toString)()   // (*)
But not here:
    (0, new Date().toString)()

Then I found out that spec-wise, (*) is very close to Python. But if implementations don’t have references then it’s also impossible to keep them around. One could produce a bound function whenever one evaluates a reference to a method, but I don’t know if it’s worth the trouble (performance and compatibility-wise).

If you picture a method invocation as a single construct (and not as first evaluating and then applying the () operator) then things do make sense – evaluating is a different thing and simply gives you back the function you put there. And, thankfully, with strict mode, things fail fast if you forget to bind() a method.

Dr. Axel Rauschmayer
axel at


More information about the es-discuss mailing list