js 箭头函数 this

箭头函数没有this,所以箭头函数中的this指向上一层作用于的this

var obj = {
    name:'name1',
    age:18,
    getName:()=>{
        console.log('getName:',this)
    },
    getAge:function(){
        console.log('getAge:',this)
    }
}    

console.log('全局window',this)
obj.getName()
obj.getAge()

参考文档

猜你喜欢

转载自blog.csdn.net/Cribug8080/article/details/88526698