admin管理员组文章数量:1221766
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')
})
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')
})
Share
Improve this question
edited Aug 3, 2016 at 6:54
Mulan
135k34 gold badges238 silver badges274 bronze badges
asked Apr 18, 2016 at 4:08
G SisG Sis
1992 silver badges7 bronze badges
5
|
1 Answer
Reset to default 18app.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.
本文标签: javascriptes6 harmony arrow functions in express handlersStack Overflow
版权声明:本文标题:javascript - es6 harmony arrow functions in express handlers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739271357a2155830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
this
value (You can read more about it here). So in a case like this where you won't need to usethis
, using an arrow function would be fine. – Saad Commented Apr 18, 2016 at 4:37