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";
I wonder about the third line - and with me JSLint, which calls this line a "Bad Assigment".
But it works!
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 functions can return a single value. To return multiple values from a function, you can pack the return values as elements of an array or as properties of an object.
An lvalue refers to an object that persists beyond a single expression. An rvalue is a temporary value that does not persist beyond the expression that uses it.
It's a ground rule. JavaScript follows this rule, functions always return something. In the case where you don't want to return a value, something else exists.
When a return statement is used in a function body, the execution of the function is stopped. If specified, a given value is returned to the function caller. For example, the following function returns the square of its argument, x , where x is a number. If the value is omitted, undefined is returned instead.
Yes, the standard permits functions to returns references. No, you cannot write such a function in Javascript. ;)
<...> the left-hand operand of an assignment is expected to produce a reference. <...> 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. http://es5.github.io/#x8.7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With