<分区>
是否可以在类函数中访问 class
本身:
class MyClass {
static get myFunction() { return "foo"; }
constructor() {
console.log(MyClass.myFunction); // "foo" -- it works when using its name. This is what we want but without using the name
console.log(this.myFunction); //undefined
console.log(this.prototype.myFunction); //Cannot read property 'myFunction' of undefined
}
}
new MyClass();
是否有可能实现与使用 MyClass.myFunction()
相同的效果并在不使用类名的情况下访问 static
方法(在这种情况下没有在这个例子中使用 MyClass
?
类似this.master.myFunction()
的东西(我只是在这里制作master
,显然不叫master)
JSBin:https://jsbin.com/hawituxosu/1/edit?js,console
这可能吗?谢谢!