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。

 

posted @ 2021-05-11 23:20  小庄的blog  阅读(52)  评论(0编辑  收藏  举报