noGlobalObjectCalls
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/correctness/noGlobalObjectCalls
Since: v1.0.0
Sources:
- Same as:
no-obj-calls
Disallow calling global object properties as functions
ECMAScript provides several global objects that are intended to be used as-is. Some of these objects look as if they could be constructors due their capitalization (such as Math and JSON) but will throw an error if you try to execute them as functions.
The ECMAScript 5 specification makes it clear that both Math and JSON cannot be invoked: The Math object does not have a [[Call]] internal property; it is not possible to invoke the Math object as a function.
The ECMAScript 2015 specification makes it clear that Reflect cannot be invoked: The Reflect object also does not have a [[Call]] internal method; it is not possible to invoke the Reflect object as a function.
The ECMAScript 2017 specification makes it clear that Atomics cannot be invoked: The Atomics object does not have a [[Call]] internal method; it is not possible to invoke the Atomics object as a function.
And the ECMAScript Internationalization API Specification makes it clear that Intl cannot be invoked: The Intl object does not have a [[Call]] internal method; it is not possible to invoke the Intl object as a function.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Math is not a function.
> 1 │ var math = Math();
│ ^^^^
2 │
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Math is not a function.
> 1 │ var newMath = new Math();
│ ^^^^
2 │
code-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Json is not a function.
> 1 │ var json = JSON();
│ ^^^^
2 │
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Json is not a function.
> 1 │ var newJSON = new JSON();
│ ^^^^
2 │
code-block.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Reflect is not a function.
> 1 │ var reflect = Reflect();
│ ^^^^^^^
2 │
code-block.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Reflect is not a function.
> 1 │ var newReflect = new Reflect();
│ ^^^^^^^
2 │
code-block.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Atomics is not a function.
> 1 │ var atomics = Atomics();
│ ^^^^^^^
2 │
code-block.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Atomics is not a function.
> 1 │ var newAtomics = new Atomics();
│ ^^^^^^^
2 │
code-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Intl is not a function.
> 1 │ var intl = Intl();
│ ^^^^
2 │
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Intl is not a function.
> 1 │ var newIntl = new Intl();
│ ^^^^
2 │