`this`: methods versus functions

Axel Rauschmayer axel at rauschma.de
Thu Nov 10 06:58:44 PST 2011

>> I wonder if it made a difference if `this`was always stored in an
>> environment (instead of an execution context). Then block lambdas could find
>> them via the scope chain.
> If I understand you correctly, then yes, this is definitely possible
> in principle, and in fact corresponds to the standard model of objects
> as straightforward records-of-closures (closing over `this'). But you
> could not use prototypes directly anymore, because you would need to
> close their methods over `this' as well when you construct an object.
> IOW, this would require a more class-style approach to inheritance.

I don’t understand. Can you give an example? I thought that simply turning `this` into a parameter (under the hood, like a hidden first parameter that all functions have) would not change anything:

obj.method(arg1, arg2) => obj.method<obj>(arg1, arg2)
func(arg1, arg2) => func<undefined>(arg1, arg2)

(The hidden parameter is in angle brackets.)

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/28d85ef2/attachment.html>

More information about the es-discuss mailing list