<script>
console.log(1, this)//===>window
this.name = '@@@@'
console.log(2, this)//===>window
setTimeout(function () {
console.log(3, this);//===>window
}, 1000);
setTimeout(() => {
console.log(4, this); //===>window
}, 1000);
b1.onclick = function () {
setTimeout(() => {
console.log(5, this); //===><button id="b1">我是b1按钮</button>
}, 1000);
}
var obj = {
name: "张三",
eat: function () {
console.log(6, this.name);//===>obj对象
},
drink: () => {
console.log(7, this.name);//===>window,上下文
},
work() {
console.log(8, this.name);//===>obj对象
}
}
obj.eat()//====>张三
obj.drink()//====>@@@
obj.work()//===>张三
</script>