es6 static

static 定义的是类的方法只有类能调用,而普通方法是实例的方法只有类实例能调用。变量也一样。

class A {
    static fn() {
        console.log('sss');
    }
    fn2() {
        console.log('www');
    }
}

let a = new A();

a.fn(); // 报错
A.fn();    
a.fn2();
A.fn2(); // 报错
原文地址:https://www.cnblogs.com/91allan/p/6184905.html