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