简体   繁体   中英

es6 call class methods from within same class

I'm trying to call a class method in my class form a neighboring method as shown in the example below.

import blah from './blaha';

export default class myclass{
  constructor(con) {
    this.config = con;
  }

  async meth1(paramA) {
    //do_stuff...
  }

    meth2(paramB) {
     //attempt to call meth1()
  }

}

I would like to call a method from within a different method using es6 class styles.

Use this

import blah from './blaha';

export default class myclass{
  constructor(con) {
    this.config = con;
  }

  async meth1(paramA) {
    //do_stuff...
  }

  meth2(paramB) {
     this.meth1()
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM