簡體   English   中英

es6和諧箭頭在快遞處理器中起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM