首页 > Web开发 > 详细

js中this指向

时间:2021-05-12 00:15:21      阅读:41      评论:0      收藏:0      [点我收藏+]

谁调用它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。

 

js中this指向

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!