1.箭頭函數(shù)不綁定 arguments,取而代之用 rest 參數(shù)(…a) => {console.log(a)}解決
2.箭頭函數(shù)不能當(dāng)做 Generator 函數(shù),不能使用 yield 關(guān)鍵字
3.箭頭函數(shù)沒(méi)有原型屬性:
(()=>{ }).prototype // undefined
(function a(){}).prototype // {constructor: ?}
ES6 中新增了箭頭函數(shù)這種語(yǔ)法,箭頭函數(shù)以其簡(jiǎn)潔性和方便獲取 this 的特性:
普通函數(shù)下的 this:
- 在普通函數(shù)中的 this 總是代表它的直接調(diào)用者,在默認(rèn)情況下,this 指的是 window,
- 在嚴(yán)格模式下,沒(méi)有直接調(diào)用者的函數(shù)中的 this 是 undefined 使用
- call,apply,bind(ES5 新增)綁定的,this 指的是 綁定的對(duì)象
箭頭函數(shù)中的 this:
- 箭頭函數(shù)沒(méi)有自己的 this, 它的 this 是繼承而來(lái); 默認(rèn)指向在定義它時(shí)所處的對(duì)象(宿主對(duì)象),
- 而不是執(zhí)行時(shí)的對(duì)象, 定義它的時(shí)候,可能環(huán)境是 window,也有可能是其他的。