箭头函数

基本使用

let hello = (name) => {
    console.log(name);
}
hello('cht');

箭头函数中得this

let p = {
    name:'cht',
    say:()=> {
        console.log(this.name);
    }
}
p.say();

// 如果是:ES5中,这个this指得是 p这个对象,谁调用指向谁
// ES6中这个this指向的是全局对象 window
// 例如我们常在 Vue中使用箭头函数,这个时候this 指向的就是 new Vue 的 实例对象。

Last Updated: 1/31/2021, 10:53:10 PM