This blog post explains that classes have lexical inner names, just like named function expressions.

The inner names of function expressions #

You may know that function expressions have lexical inner names:

const fac = function me ( n ) { if (n > 0 ) { return n * me(n -1 ); } else { return 1 ; } }; console .log(fac( 3 ));

The name me of the named function expression becomes a lexically bound variable that is unaffected by which variable currently holds the function.

The inner names of classes #

Interestingly, ES6 classes also have lexical inner names that you can use in methods (constructor methods and regular methods):

class C { constructor () { console .log( `constructor: ${C.prop} ` ); } logProp() { console .log( `logProp: ${C.prop} ` ); } } C.prop = 'Hi!' ; const D = C; C = null ; new C().logProp(); new D().logProp();

(In the ES6 spec the inner name is set up by the dynamic semantics of ClassDefinitionEvaluation.)

Acknowledgement: Thanks to Michael Ficarra for pointing out that classes have inner names.