总结:
- 全局环境的this指向window
- 箭头函数的this指向函数创建时指的this,普通函数随着被调用所处的环境不同this指向会发生变化
- 对象里的普通函数指向被调用的对象
同时也可以参考下面这个链接
https://javascript.ruanyifeng.com/oop/this.html
总结:
this就是属性或方法“当前”所在的对象。
箭头函数普通函数的区别:
var a ={
test:function(){
console.log(this)
},
test1:()=>{
console.log(this)
}
}
a.test();
// Object { test: test(),test1:test1() }
a.test1();
// output window