在调用静态方法时,应该直接使用类名而不是实例来调用。例如:
class MyClass {
static myMethod() {
console.log("Hello");
}
myOtherMethod() {
// 此处引用未绑定的静态方法
MyClass.myMethod();
}
}
const instance = new MyClass();
// 此处也应该直接使用类名来调用静态方法
MyClass.myMethod();
应该改为:
class MyClass {
static myMethod() {
console.log("Hello");
}
myOtherMethod() {
MyClass.myMethod();
}
}
MyClass.myMethod();