88 lines
2.3 KiB
Plaintext
Raw Normal View History

== 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:
2021-04-28 16:49:39 +02:00
* ``++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.
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
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
2021-04-28 16:49:39 +02:00
function fun() {
if (arguments.length == 0) { // Compliant
// do something
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
result = 17;
args++;
++result;
const obj = { set p(arg) { } };
let result;
try { /* ... */ } catch (args) { }
function x(arg) { /* ... */ }
function args() { /* ... */ }
const y = function fun() { /* ... */ };
2021-04-28 16:49:39 +02:00
function fun() {
if (arguments.length == 0) {
// do something
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove the modification of "xxx".
Do not use "xxx" to declare a [variable|parameter|class|function] - use another name.
'''
== Comments And Links
(visible only on this page)
=== deprecates: S1514
=== is related to: S5806
=== on 10 Oct 2014, 17:12:00 Ann Campbell wrote:
Assigned to you for review.
=== on 16 Mar 2015, 07:34:41 Linda Martin wrote:
Reviewed.
endif::env-github,rspecator-view[]