V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
bitsmix
V2EX  ›  问与答

一个 javascript 的小问题

  •  
  •   bitsmix · 2012-08-19 00:57:00 +08:00 · 3002 次点击
    这是一个创建于 4271 天前的主题,其中的信息可能已经有所发展或是发生改变。
    简单来说就是我创建了一个 String.prototype 的方法。只有 return this

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

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

    那边看起来更方便

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


    Thanks!
    2 条回复    1970-01-01 08:00:00 +08:00
    dreampuf
        1
    dreampuf  
       2012-08-19 01:03:01 +08:00   ❤️ 1
    转一个,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
        2
    bitsmix  
    OP
       2012-08-19 01:27:50 +08:00
    @dreampuf thx, 我后来也发现这个是一个重复的问题了。之前脑子卡壳了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1106 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:53 · PVG 06:53 · LAX 15:53 · JFK 18:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.