`this`: methods versus functions

Axel Rauschmayer axel at rauschma.de
Wed Nov 9 16:17:04 PST 2011

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

Agreed. The global object assumption is too prevalent in non-strict mode, so that one is out. Strict mode *might* still be OK. In any case, if we have both block lambdas and shorter method syntax (*) then everyone will automatically do the right thing in practically all cases. That would be really cool.

(*) I recently heard a story of someone being surprised by seeing the word “function” in object literals – “Isn’t that supposed to be a method? Why is it called a function, then?”

Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111110/0553d5d3/attachment.html>

More information about the es-discuss mailing list