1.全局作用域或者普通函数中this指向全局对象window(注意定时器里面的this指向window)
console.log(this); //windowfunction fn(){console.log(this); //window}fn();setTimeout(function(){ //windowconsole.log(this);},1000)
2.方法调用中谁用this指向谁
var o={sayHi:function(){console.log(this) this指向的是o这个对象}}var btn=document.querySelector('button');btn.onclick=fuction(){ this指向的是btn这个对象console.log(this);}
3.构造函数中this指向构造函数的实例
function Fun(){console.log(this); //this 指向的是fun 实例对象}var fun=new Fun();
