ES5:
function f (a, b) {
return a + b;
}
-->ES6
let f = (a, b) => a + bsegmentfault
ES5:
function f (a, b) {
console.log('Hello ES6.');
return a + b;
}
-->ES6
let f = (a, b) => {
console.log('Hello ES6.');
return a + b;
}
若是把函數寫在代碼塊裏面,有return須要本身寫return。函數
什麼時候不能使用箭頭函數:
https://segmentfault.com/q/1010000006958015
感受這篇文章講的很詳細。io