Ecmascript函数的真实世界示例返回Reference? [英] Real world examples of Ecmascript functions returning a Reference?

查看:141
本文介绍了Ecmascript函数的真实世界示例返回Reference?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 EcmaScript规范,第8.7节参考规范类型


参考类型用于解释此类运算符的行为as delete typeof ,以及赋值运算符。 [...]引用是已解析的名称绑定。

The Reference type is used to explain the behaviour of such operators as delete, typeof, and the assignment operators. […] A Reference is a resolved name binding.

允许函数调用返回引用。纯粹为了宿主对象而承认这种可能性。此规范定义的内置ECMAScript函数没有返回引用,并且没有为用户定义的函数提供返回引用。

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.

最后两句话让我印象深刻。有了这个,你可以做一些事情,比如 coolHostFn()= value 有效的语法,顺便说一句。所以我的问题是:

Those last two sentences impressed me. With this, you could do things like coolHostFn() = value (valid syntax, btw). So my question is:

是否有任何EcmaScript实现定义了导致 Reference 值的主机函数对象? / p>

Are there any EcmaScript implementations that define host function objects which result in Reference values?

推荐答案

谷歌Chrome的引擎非常有效。但是,你会注意到在控制台中你会得到一个 ReferenceError:在执行以下内容时,在赋值中的左侧无效

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");

然而,这是一个早期错误,因为v8的ECMAScript实现,如果它正确的话应该可行在假设引用错误之前执行 myFunc

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.

那么,在v8的当前实现中?是和否。它默认实现(由于语言的结构),但是功能因不同的问题而停止。 coolHostFn()= value 不应该返回错误,并且确实应该能够正确执行。但是 3 = 4 应该肯定会返回左侧分配错误。

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.

(以下是问题/票据以防任何人想要加入...... http://code.google.com/p/v8/issues/detail?id=838

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

这篇关于Ecmascript函数的真实世界示例返回Reference?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆