1、this 对象 是在运行时基于函数的执行环境绑定的
- 在全局函数中,this 等于 window,而当函数被作为某个对象的方法调用时,this 等于那个对象
- 也就是说 this 关键字总是指代调用者,也就是谁调用我,我就指向谁
var k = 10;
function test(){
this.k = 20;
}
test(); // 等价于 window.test(),此时this 指向 window
console.log(test.k); // undefined
console.log(window.k); // 20