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

Brendan Eich brendan at mozilla.org
Mon Jul 27 22:52:30 UTC 2015


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


More information about the es-discuss mailing list