js中this具体的指向
- 事件触发时,this是指事件前面的元素
box.onclick = function(){
console.log(this); //this是指box该元素
}
- 如果直接调用或是在定时器中,this指window对象
console.log(this); //this是指window元素
setTimeout(function(){
conlsole.log(this); //this是指window元素
},100)
- 在对象里面,this指的是函数前面的对象
var obj={
run:function fm(){
console.log(this); //this是指run
}
}