这样写是可以正常调用的
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呢?
相关分类