Real world examples of Ecmascript functions returning a Reference?

后端 未结 1 537
情书的邮戳
情书的邮戳 2020-11-29 06:34

ECMAScript specification, section 8.7 The Reference Specification Type states:

The Reference type is used to explain the behaviour of such o

相关标签:
1条回答
  • 2020-11-29 07:11

    Google Chrome's engine works very much in this way. However, you'll notice in the console you'll get an ReferenceError: Invalid left-hand side in assignment when executing the following:

    var myObj = new Object();
    function myFunc() {
        myObj.test = "blah";
        return myObj;
    }
    myFunc() = new String("foobar");
    

    This is an Early Error, however, and because the v8's ECMAScript implementation, this should work if it properly executes myFunc before assuming the reference error.

    So, in v8's current implementation? Yes and No. It is implemented by default (due to how the language is structured), however the capability is halted by a different issue. coolHostFn() = value should not return an error, and should indeed be able to execute properly. However 3=4 should most certainly return a left-hand side assignment error.

    Not exactly an answer to your question, but I hope it helps clarify why it doesn't work.

    (Here's the Issue/Ticket in case anyone wants to chime in... http://code.google.com/p/v8/issues/detail?id=838 )

    0 讨论(0)
提交回复
热议问题