组件中的函数的两种不同写法为什么会导致this指针的指向不同?
发布于 6 年前 作者 gangshao 12072 次浏览 来自 官方Issues

在component.js中

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

但是

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

有大神知道为什么嘛

2 回复

补习一下es6吧

箭头函数没有this指向

回到顶部