Created
October 30, 2010 19:46
-
-
Save nzakas/655672 to your computer and use it in GitHub Desktop.
New behavior of arguments in ECMAScript 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Section 10.6 Note 1 in ECMA-262, 5th Edition says: | |
* | |
* For non-strict mode functions the array index (defined in 15.4) named data | |
* properties of an arguments object whose numeric name values are less than | |
* the number of formal parameters of the corresponding function object initially | |
* share their values with the corresponding argument bindings in the function's | |
* execution context. This means that changing the property changes the | |
* corresponding value of the argument binding and vice-versa. | |
* | |
* Thus, the following function should work. | |
*/ | |
function doAdd(num1, num2) { | |
if(arguments.length == 1) { | |
arguments[1] = 10; | |
} | |
alert(arguments[0] + num2); | |
} | |
/* | |
* I believe this line should work in non-strict ECMAScript 5. | |
* In Minefield latest nightly, though, this returns NaN | |
* instead of 20. In strict mode, this behavior would be correct. | |
*/ | |
doAdd(10); //Should return 20, but returns NaN in Minefield 2010-Oct-30. | |
doAdd(30, 20); //50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment