4-js基础讲解this篇
什么是this?
指代案例
指代window
console.log(this.document === document); // true (document === window.document)
console.log(this === window); // true
this.a = 37; //相当于创建了一个全局变量a
console.log(window.a); // 37var x = 1;
function test(){
alert(this.x);
}
test(); // 1指代调用对象本身
总结
参考文献
Last updated
