Статические методы
class Obj { static myMethod(msg) { console.log('static', msg); } myMethod(msg) { console.log('instance', msg); } } Obj.myMethod(1); // static 1 var instance = new Obj(); instance.myMethod(2); // instance 2
Самостоятельный доступ
class A { constructor( input ) { this.tight = A.getResult( input ) //this.tight = this.constructor.getResult( input ) } static getResult( input ) { return input * 2 } } let instanceA = new A( 4 ); console.log( "A.tight", instanceA.tight ); //A.tight 8
Замечание
this.tight = this.constructor.getResult( input )
такой же, как
this.tight = A.getResult( input )