[英]es6 harmony arrow functions in express handlers
Is there a reason not to use arrows instead of regular function expressions in expressjs for handlers in middleware? 是否有理由不在中间件中为处理程序使用箭头而不是常规函数表达式?
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();
})
is the same as 是相同的
app.get('/', function(req,res,next) {
next();
}.bind(this))
In most cases you are not going to use 'this'(which will be probably undefined) in the handlers, so you are free to use arrow functions. 在大多数情况下,您不会在处理程序中使用“this”(可能未定义),因此您可以自由使用箭头函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.