Questions about the wrapper method of es6 class class

encapsulate a method with class:

const test=calss{
constructor(){
..
this.init()
}
..
init(){
  
 //return new Promise( function (resolve, reject) {})

}
}

init () is put into constructor, but when you go to execute new test (, is not a function, will prompt. Then is not a function, must remove this.init (), from constructor and then execute new test (and then execute new test (, and then how can it be executed properly? how can it be executed like this?

Jun.15,2021

return this.init ()

because you really don't have a then method defined, and you don't know why.



class Test {
  constructor() {
    return this.init()
  }

  init() {
    return new Promise((resolve, reject) => {
      console.log('I am a text class.')
      resolve();
    })
  }
}

new Test().then(a => console.log('hello world'))

return this.init ()

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ec68-2c422.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ec68-2c422.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?