95 lines
2.5 KiB
Plaintext
95 lines
2.5 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 global properties. They are available in all environments. Some examples are:
|
|
|
|
* Global objects: `Object`, `Function`, `Error`, ...
|
|
* Global object function properties: `eval()`, `isNan()`, `parseFloat()`, `decodeURI()`, ...
|
|
* Global object value properties: `undefined`, `NaN`, `Infinity`
|
|
* Identifiers with special meanings: `arguments`
|
|
|
|
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
|
|
}
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words[Reserved words]
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers_with_special_meanings[Identifiers with special meanings]
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects[Global Objects]
|
|
|
|
|
|
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[]
|