YoungSx
7/21/2017 - 8:37 AM

ES6箭头函数可解决this作用域问题 #tags: ES6,Javascript

ES6箭头函数可解决this作用域问题 #tags: ES6,Javascript

() => {
    console.log(this.infoHash) // 此处 this 非当前箭头函数
}

对比

function () {
    console.log(this.infoHash) // 此处 this 为当前匿名函数
}