Original | JavaScript | |
The environment model as presented so far focuses on how functions can refer to their parameters, locally declared names, and names that are declared outside the function. We achieve this by evaluating statements and expressions with respect to a current environment. It does not specify how we keep track of environments as computation proceeds. For example, when we evaluate an expression f(x) + y, we need to evaluate x in the current environment, establish as the new current environment the environment of f extended by a binding of its parameter to the value of x, and evaluate the body of f in this extended environment. But what environment should we use for evaluating y after f returns? In this section, we extend the Exercise 3.8 shows that the presence of assignments makes the result of a program depend on the order in which the operands of an operator combination are evaluated. To remove ambiguities that arise from this, the JavaScript standard specifies left-to-right evaluation of operands. As an example, consider the evaluation of the arithmetic expression statement 1 + (2 * 3); The expression is decomposed into its operands 1 and 2 * 3, followed by the instruction to add their results. |