这样写是可以正常调用的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呢?
添加回答
举报
0/150
提交
取消