我希望能够从实例和类中访问一个方法:
class AClass {
// I want to make this both static and normal
method() {
console.log("Method called");
}
}
我希望能够从实例访问
static
方法(就像在python中使用@staticmethod
)但我不能,因为它给出了一个错误:
class AClass {
static method() {
console.log("Method called");
}
}
AClass.method(); // this works
(new AClass).method(); // this doesn't work