Syntax shortcut for accessing properties on the current context ("this")

Matthew Robb matthewwrobb at gmail.com
Tue Jul 28 12:32:34 UTC 2015


does it seem reasonable though that if properties get initializers in the
class body that they could be considered "in scope" to everything else
defined in the class body?
On Jul 27, 2015 6:52 PM, "Brendan Eich" <brendan at mozilla.org> wrote:

> Michael McGlothlin wrote:
>
>> I'd rather that prop just match the object the method is actually
>> attached to, regardless of the context of 'this', before continuing
>> searching the tree. Familiar as its done that way in many languages,
>>
> You mean static (applied to types, including fields in objects) languages?
> Those are not like JS in the critical sense that a free variable reference
> in a JS method, e.g.
>
> class C {
>   m() { return x; }
>   ...
> }
>
> should resolve per lexical scope, not per an implicit `this.` that may or
> may not apply, depending on whether 'x' in this => true.
>
> If you say it always means `this.x` then there's no way to refer to an
> outer lexical variable, x.
>
> So there has to be some prefix, if not `this.`, to distinguish.
>
> /be
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150728/869c89fa/attachment.html>


More information about the es-discuss mailing list