這樣寫是可以正常調(diào)用的router.route('/account')
.get(function (req, res, next) {
User.find()
.then(users => res.json(users))
.catch(err => next(err));
});我覺得這段代碼可以簡(jiǎn)化成router.route('/account')
.get(function (req, res, next) {
User.find()
.then(res.json)
.catch(next);
});可是采用第二種寫法的時(shí)候在express的源碼中會(huì)報(bào)錯(cuò)就是在var app = this.app;這一行,debug發(fā)現(xiàn)this值是undefined,在js里面,對(duì)象的方法,this不是應(yīng)該直接指向該對(duì)象嗎?為什么這里this也就是res會(huì)是undefined呢?
js中this指向的問題
夢(mèng)里花落0921
2018-09-18 09:09:26
