是否有理由不在中间件中为处理程序使用箭头而不是常规函数表达式?
app.use(mountSomething())
router.use(mountSomethingElse())
app.get('/', (req,res,next)=> {
next();
})
route.get('/path', (req,res,next)=>{
res.send('send')
})
答案 0 :(得分:11)
app.get('/', (req,res,next)=> {
next();
})
与
相同app.get('/', function(req,res,next) {
next();
}.bind(this))
在大多数情况下,您不会在处理程序中使用“this”(可能未定义),因此您可以自由使用箭头函数。