V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
bitsmix
V2EX  ›  问与答

一个 javascript 的小问题

  •  
  •   bitsmix · Aug 19, 2012 · 3656 views
    This topic created in 5012 days ago, the information mentioned may be changed or developed.
    简单来说就是我创建了一个 String.prototype 的方法。只有 return this

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

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

    那边看起来更方便

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


    Thanks!
    2 replies    1970-01-01 08:00:00 +08:00
    dreampuf
        1
    dreampuf  
       Aug 19, 2012   ❤️ 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
       Aug 19, 2012
    @dreampuf thx, 我后来也发现这个是一个重复的问题了。之前脑子卡壳了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3106 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:35 · PVG 11:35 · LAX 20:35 · JFK 23:35
    ♥ Do have faith in what you're doing.