Skip to content

Instantly share code, notes, and snippets.

@nzakas
Created October 30, 2010 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzakas/655672 to your computer and use it in GitHub Desktop.
Save nzakas/655672 to your computer and use it in GitHub Desktop.
New behavior of arguments in ECMAScript 5
/* 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