版权声明:本文转载自阿Z爱码原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:
https://blog.csdn.net/weixin_44021199/article/details/97539920
1.定时器中:this ->window
setInterval(function(){
*this*
},10)
2.函数中:this ->window
function a(){
console.log(*this*);
}
a();
3. this -> oDiv 对当前对象的引用
oDiv.onclick = function(){
*this*
}
4. this -> obj
var obj = {
name:'zs',
age:20,
say:function(){
console.log(this.name + "haha");
}
}
obj.say();
5. this -> new出来的实例化对象
function Person(){
this.name = 'zs';
}
var p1 = new Person();