admin管理员组文章数量:1389757
ECMAScript specification, section 8.7 The Reference Specification Type states:
The
Reference
type is used to explain the behaviour of such operators asdelete
,typeof
, and the assignment operators. […] A Reference is a resolved name binding.Function calls are permitted to return references. This possibility is admitted purely for the sake of host objects. No built-in ECMAScript function defined by this specification returns a reference and there is no provision for a user-defined function to return a reference.
Those last two sentences impressed me. With this, you could do things like coolHostFn() = value
(valid syntax, btw). So my question is:
Are there any ECMAScript implementations that define host function objects which result in Reference
values?
ECMAScript specification, section 8.7 The Reference Specification Type states:
The
Reference
type is used to explain the behaviour of such operators asdelete
,typeof
, and the assignment operators. […] A Reference is a resolved name binding.Function calls are permitted to return references. This possibility is admitted purely for the sake of host objects. No built-in ECMAScript function defined by this specification returns a reference and there is no provision for a user-defined function to return a reference.
Those last two sentences impressed me. With this, you could do things like coolHostFn() = value
(valid syntax, btw). So my question is:
Are there any ECMAScript implementations that define host function objects which result in Reference
values?
- 3 Related? stackoverflow./questions/3709866/… – bfavaretto Commented Oct 29, 2012 at 17:14
- Yes, I think so. That question proves the syntax I used above would be valid :-) – Bergi Commented Oct 29, 2012 at 17:44
-
I just googled
"returns a reference" javascript
and looked through the first through pages, but there was nothing. – Nathan Commented Oct 29, 2012 at 19:07
1 Answer
Reset to default 7Google 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./p/v8/issues/detail?id=838 )
本文标签: javascriptReal world examples of Ecmascript functions returning a ReferenceStack Overflow
版权声明:本文标题:javascript - Real world examples of Ecmascript functions returning a Reference? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744657368a2618046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论