Javascript es6从同一类中调用类方法
我试图从相邻的方法调用我的类中的类方法,如下例所示Javascript es6从同一类中调用类方法,javascript,node.js,oop,ecmascript-6,Javascript,Node.js,Oop,Ecmascript 6,我试图从相邻的方法调用我的类中的类方法,如下例所示 import blah from './blaha'; export default class myclass{ constructor(con) { this.config = con; } async meth1(paramA) { //do_stuff... } meth2(paramB) { //attempt to call meth1() } } 我想使用es6类样式
import blah from './blaha';
export default class myclass{
constructor(con) {
this.config = con;
}
async meth1(paramA) {
//do_stuff...
}
meth2(paramB) {
//attempt to call meth1()
}
}
我想使用es6类样式从不同的方法中调用一个方法。使用this
import blah from './blaha';
export default class myclass{
constructor(con) {
this.config = con;
}
async meth1(paramA) {
//do_stuff...
}
meth2(paramB) {
this.meth1()
}
}
主要是我试图将一些对象传递给类中的另一个方法来处理它的一些工作。我一直看到的一个问题是,如果我在另一个方法中的一个单独函数中,我就不能调用方法,就像总是:
this.meth1()
。“如果我在另一个方法中的一个单独函数中,我就不能调用一个方法”听起来像是then的翻版。我读到这篇文章时会想,“不要使用meth”也有类似的问题,有一个子类。除非在父类中声明,否则不能调用子类中的相邻方法。@kiwicomb123继承就是这样工作的。你们应该在父类中声明方法,并在兄弟类中使用。我从来并没有提到过任何关于继承的事情。并非子类的所有方法都与其同级相关。