“在ES6中为什么要省略像这样的内容?”
class Foo {
myMethod(){
// do something with 'bar'
}
constructor(){
this.myMethod();
}
otherMethod(){
this.myMethod();
}
}
我知道在构造函数中定义函数,或者在类外部定义函数然后使用 myMethod()
是可行的。然而,作为其他语言的用户,我惊讶地发现有类,但没有本地(或私有)方法。我在互联网上找不到这个被省略的原因。