简单理解,this指向的是该this所在的最里层的object对象。
1、函数不是object对象,所以没有写在object对象里的函数调用this会指向window
2、构造函数是object对象,所以在构造函数中调用this会指向该构造函数
3、html元素是object元素,所以在html元素中调用this会指向该元素
4、函数1 return 函数2,函数2 return this,该this会指向window
例:
let obj ={
fun1:function(){
returnfunction(){
returnthis;
}
},
};
console.log(obj.fun1()());//window