72 lines
2.0 KiB
Plaintext
72 lines
2.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
JavaScript has special identifiers that, while not reserved, still should not be used as identifiers. They form the JavaScript standard built-in objects and are available in all environments. They include identifiers like:
|
|
|
|
* ``++eval++`` - Evaluates a string as JavaScript code.
|
|
* ``++arguments++`` - Used to access function arguments through indexed properties. It exists only inside function declarations and function expressions.
|
|
* ``++undefined++`` - Returned for values and properties that have not yet been assigned.
|
|
* ``++NaN++`` - Not a Number; returned when math functions fail.
|
|
* ``++Infinity++`` - When a number exceeds the upper limit of the floating point numbers.
|
|
|
|
These words should not be bound or assigned, because doing so would overwrite the original definitions of these identifiers. What's more, assigning or binding some of these names will generate an error in JavaScript strict mode code.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
eval = 17; // Noncompliant
|
|
arguments++; // Noncompliant
|
|
++eval; // Noncompliant
|
|
const obj = { set p(arguments) { } }; // Noncompliant
|
|
let eval; // Noncompliant
|
|
try { /* ... */ } catch (arguments) { } // Noncompliant
|
|
function x(eval) { /* ... */ } // Noncompliant
|
|
function arguments() { /* ... */ } // Noncompliant
|
|
const y = function eval() { /* ... */ }; // Noncompliant
|
|
|
|
function fun() {
|
|
if (arguments.length == 0) { // Compliant
|
|
// do something
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
result = 17;
|
|
args++;
|
|
++result;
|
|
const obj = { set p(arg) { } };
|
|
let result;
|
|
try { /* ... */ } catch (args) { }
|
|
function x(arg) { /* ... */ }
|
|
function args() { /* ... */ }
|
|
const y = function fun() { /* ... */ };
|
|
|
|
function fun() {
|
|
if (arguments.length == 0) {
|
|
// do something
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|