我无法在静态方法中调用类的私有或非静态方法,以下是示例:
class a {
fun1(){
console.log('fun1');
}
static staticfun(){
console.log('staticfun');
this.fun1();
}
}
a.staticfun();
我试图仅公开调用所有私有方法的staticfun方法,但是这给我带来了this.fun1
不是函数的问题。我尝试了许多使用“this”找到它的方法,但它并没有起作用。
如何在静态方法中调用私有实例方法?
fun1
设为静态的吗? - BergiPromise
构造函数反模式 b) 如果您不需要多个实例,那么没有理由将任何内容包装在class
语法中。请参考:https://dev59.com/7F0a5IYBdhLWcg3w07rt - Bergi