函数的返回值可以是JavaScript中的左值吗? [英] Can a function's return value be an lvalue in JavaScript?
问题描述
Microsoft允许使用以下语法在JScript中设置环境变量:
Microsoft allows to set environment variables in JScript with the following syntax:
var sh = WScript.CreateObject("Wscript.Shell");
var env = sh.Environment("PROCESS");
env("TEST") = "testvalue";
我想知道第三行-以及我与JSLint一起使用时,这条线称为错误评估".
I wonder about the third line - and with me JSLint, which calls this line a "Bad Assigment".
但是有效!
使函数的返回值作为左值是否兼容ECMAscript标准(例如此处)?
Is it ECMAscript standard compatible to have a function's return value as an lvalue (like here)?
如果是:一个人怎么写这样的功能?
If yes: How would one write such a function?
推荐答案
是的,该标准允许函数返回引用.不,您不能用Javascript编写这样的函数. ;)
Yes, the standard permits functions to returns references. No, you cannot write such a function in Javascript. ;)
< ...>赋值的左侧操作数应产生引用. < ...>函数调用被允许返回引用.纯粹出于宿主对象的考虑,才承认这种可能性.本规范定义的内置ECMAScript函数不会返回引用,并且用户定义的函数也无法返回参考. http://es5.github.io/#x8.7
这篇关于函数的返回值可以是JavaScript中的左值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!