组件中的函数的两种不同写法为什么会导致this指针的指向不同?

发布于 7 年前作者 gangshao12281 次浏览最后编辑 7 年前来自 issues

在component.js中

Component({
    attached:()=>{
    console.log(this) // undefined
}
})

但是

Component({
    attached: function() {
    console.log(this) // 指向当前Component
}
})

有大神知道为什么嘛

2 回复
wenmin
wenmin1 楼6 年前

补习一下es6吧

jieyi
jieyi2 楼5 年前

箭头函数没有this指向