this 存在于任何地方,this不是在定义的时候确定的,而是在调用的时候确定的
// 第一种: var box = document.getElementById('box'); box.onclick = function () { console.log(this); // 被点击的哪个元素 } // 第二种: function fn() { console.log(this); //指向Window } fn();
this 存在于任何地方,this不是在定义的时候确定的,而是在调用的时候确定的
// 第一种: var box = document.getElementById('box'); box.onclick = function () { console.log(this); // 被点击的哪个元素 } // 第二种: function fn() { console.log(this); //指向Window } fn();