`this`: methods versus functions

Brendan Eich brendan at mozilla.com
Wed Nov 9 16:06:54 PST 2011

On Nov 9, 2011, at 4:00 PM, Brendan Eich wrote:

> On Nov 9, 2011, at 3:48 PM, Axel Rauschmayer wrote:
>>>> Or are there other plans to get it solved? I would still love to see that happen, it’s a remarkably subtle source of errors. Could functions adopt the block-lambda semantics of picking up the `this` of the surrounding scope when not invoked as methods? It seems like that could work in strict mode where no one expects `this` to have a value.
>>> No, if you call such functions via object.method() references then this binds to object. You can't break such compatibility only at runtime, and only some of the time.
>> Got it. I’m assuming that’s a performance issue?
> You could say that. If we inherit by default but it's a "soft binding", then the inner function has to carry that reference with it, but in a way that can be overridden.
> We talked about lexical this for functions long ago (Jan. 2008? at Google anyway) and IIRC Mark found a subtler flaw.

But again, it's a runtime incompatible change, even ignoring performance. Code today may count on this == global in non-strict mode, or this === undefined in strict mode, for inner functions not called as methods.

Making such a runtime-incompatible change uses up one of my "five fingers of fate" and it's not to be done lightly.


More information about the es-discuss mailing list