[英]es6 harmony arrow functions in express handlers
是否有理由不在中间件中为处理程序使用箭头而不是常规函数表达式?
app.use(mountSomething())
router.use(mountSomethingElse())
app.get('/', (req,res,next)=> {
next();
})
route.get('/path', (req,res,next)=>{
res.send('send')
})
app.get('/', (req,res,next)=> {
next();
})
是相同的
app.get('/', function(req,res,next) {
next();
}.bind(this))
在大多数情况下,您不会在处理程序中使用“this”(可能未定义),因此您可以自由使用箭头函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.