ES6 允許使用 “ 箭頭 ” (=>)定義函數(shù)。
箭頭函數(shù) 填 坑。
this的指向是 向上查找 非箭頭函數(shù)的函數(shù)歸屬
this就指向這個(gè)歸屬
例如:
function fn(){
return ()=>{
console.log(this)
}
}
fn()() //this =>>window
function fn() {
return function () {
return () => {
console.log(this)
}
}
}
fn()()() //this =>>window
function fn() {
var obj={
f:function (){
return ()=> {
console.log(this)
}
}
}
return obj
}
fn().f()() //this =>>f函數(shù)