HTML and CSS Reference
In-Depth Information
results in only the last one to be reachable inside the function (except through
arguments , in which all parameters are always reachable). Listing 8.19 shows the
new behavior compared to the current one.
Listing 8.19 Using the same identifier for more than one formal parameter
"test repeated identifiers in parameters": function () {
// Syntax error in ES5 strict mode
function es3VsEs5(a, a, a) {
"use strict";
return a;
// true in ES3
assertEquals(6, es3VsEs5(2, 3, 6));
Attempts to access the caller or callee properties of the arguments
object will throw a TypeError in strict mode.
In ES3 (and non-strict ES5), the arguments object shares a dynamic rela-
tionship with formal parameters. Modify a formal parameter, and the value in the
corresponding index of the argument object is modified too. Modify a value of the
arguments object, and the corresponding parameter changes. In strict mode, this
relationship goes away and arguments is immutable, as Listing 8.20 exemplifies.
Listing 8.20 Relationship between arguments and formal parameters
function switchArgs(a, b) {
"use strict";
return [];
TestCase("ArgumentsParametersTest", {
"test should switch arguments": function () {
// Passes on ES5 strict mode
assertEquals([3, 2], switchArgs(2, 3));
// Passes on ES3
// assertEquals([2, 3], switchArgs(2, 3));
Search WWH ::

Custom Search