是否有理由不在 expressjs 中为中间件中的处理程序使用箭头而不是正则函数表达式?
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”(可能未定义),因此您可以自由使用箭头函数。
关于javascript - 快速处理程序中的 es6 和谐箭头函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685319/