Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

es6 class里的promise

$
0
0

http://stackoverflow.com/questions/38807521/es6-class-promise-chain-accessing-this


module.exports = class Xxxxx {

  start () {
    let self = this
 
    return this.before()
      .then(this.renderLayout.bind(this))
      .then(this.processError.bind(this))
  }
  
  renderLayout () {
    let self = this
    return self.compile(self.layout, self.data)
  }
 
  
  processError (err) {
    console.log(err)
  }

  before() {
    console.log('after')
  }

  after() {
    console.log('after')
  }
}

备忘一下

return this.before()
      .then(this.renderLayout.bind(this))
      .then(this.processError.bind(this))

Viewing all articles
Browse latest Browse all 14821

Trending Articles