let a = () => (
{
name:"Anna",
func: () => console.log(this.name)
}
)
let b = () => (
{
name:"Brian",
func: function(){ console.log(this.name) }
}
)
let c = function(){
return(
{
name:"Charlie",
func: function(){ console.log(this.name) }
}
)
}
let d = function(){
return(
{
name:"Denny",
func: () => console.log(this.name)
}
)
}
这 4 个函数具有混合和匹配的函数语法。调用嵌套函数时, func: with arrow 函数返回空白。
a().func() // returns blank
b().func() // returns "Brian"
c().func() // returns "Charlie"
d().func() // returns blank
我以为箭头函数保留了“this”的范围?这种行为似乎与我的想法相反。箭头函数何时超出范围?