ES6 从同一类中调用类方法

es6 call class methods from within same class

本文关键字:一类 调用 类方法 ES6      更新时间:2023-09-26

我正在尝试将类中的类方法从相邻方法中调用,如下例所示。

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()
  }
}