一个 javascript 的小问题

2012-08-19 00:57:00 +08:00
 bitsmix
简单来说就是我创建了一个 String.prototype 的方法。只有 return this

结果从 string 变成了 object 这是为啥呢?

更详细的内容我贴在 StackOverflow 了。

那边看起来更方便

http://stackoverflow.com/questions/12020463/javascript-string-object-v-s-just-string


Thanks!
3011 次点击
所在节点    问与答
2 条回复
dreampuf
2012-08-19 01:03:01 +08:00
转一个,stackoverflow已经有人回答你了。
http://stackoverflow.com/questions/5146591/javascript-wtf-a-string-prototypes-this-doesnt-return-a-string
The following steps are performed when control enters the execution context for function code contained in function object F, a caller provided thisValue, and a caller provided argumentsList:

If the function code is strict code, set the ThisBinding to thisValue.
Else if thisValue is null or undefined, set the ThisBinding to the global object.
Else if Type(thisValue) is not Object, set the ThisBinding to ToObject(thisValue).
Else set the ThisBinding to thisValue
bitsmix
2012-08-19 01:27:50 +08:00
@dreampuf thx, 我后来也发现这个是一个重复的问题了。之前脑子卡壳了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/45510

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX