js中this指向

谁调用它this就指定谁,但:

1)  a.b.fun();   this是b

2)  var f = a.b.fun;   f(); (等价于window.f() )    this是window;

3)  在new函数时: this指向的是所new 出来的函数。但如果存在return 且返回一个对象时(null 除外),function() { this.x=y; return {} } ,  获取这个对象时, 无法获取里面 fun.x //undefined。

原文地址:https://www.cnblogs.com/zjazn/p/14757927.html