New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day12:写出执行结果,并解释原因 #48
Comments
答案 |
这里并不是因为赋值给 f ,相当于f(),所以this指向window的。 var foo = {
bar: function(){
return this.baz;
},
baz:1
}
console.log(typeof (foo.bar=foo.bar)()); 下面简单从规范的角度判断这个this指向,可以分以下几个步骤: 1.计算 MemberExpression 的结果赋值给 ref 2.判断 ref 是不是一个 Reference 类型
|
解释下这两个步骤: 2、Reference 是规范类型的一种。如果通过 GetValue 方法从 Reference 类型中获取值,则该 MemberExpression 返回结果不再是 Reference 类型。 |
感谢提出指正Thanks♪(・ω・)ノ |
从 《你不知道的JavaScript 上卷》中有这么一个例子 |
个人想法: |
我也觉得这样更容易理解。从规范的角度去理解可能也行,但这不就是间接说明如果没有阅读过规范,这道题就做不出来了吗?难不成每个人都要阅读规范。。? |
这是属于this隐式丢失三项中的,函数别名。 |
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
The text was updated successfully, but these errors were encountered: