跳转到内容

noGlobalObjectCalls

此内容尚不支持你的语言。

Diagnostic Category: lint/correctness/noGlobalObjectCalls

Since: v1.0.0

Sources:

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.

var math = Math();
code-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Math is not a function.

> 1 │ var math = Math();
^^^^
2 │

var newMath = new Math();
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Math is not a function.

> 1 │ var newMath = new Math();
^^^^
2 │

var json = JSON();
code-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Json is not a function.

> 1 │ var json = JSON();
^^^^
2 │

var newJSON = new JSON();
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Json is not a function.

> 1 │ var newJSON = new JSON();
^^^^
2 │

var reflect = Reflect();
code-block.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Reflect is not a function.

> 1 │ var reflect = Reflect();
^^^^^^^
2 │

var newReflect = new Reflect();
code-block.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Reflect is not a function.

> 1 │ var newReflect = new Reflect();
^^^^^^^
2 │

var atomics = Atomics();
code-block.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Atomics is not a function.

> 1 │ var atomics = Atomics();
^^^^^^^
2 │

var newAtomics = new Atomics();
code-block.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Atomics is not a function.

> 1 │ var newAtomics = new Atomics();
^^^^^^^
2 │

var intl = Intl();
code-block.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Intl is not a function.

> 1 │ var intl = Intl();
^^^^
2 │

var newIntl = new Intl();
code-block.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Intl is not a function.

> 1 │ var newIntl = new Intl();
^^^^
2 │

function area(r) {
return Math.PI * r * r;
}
var object = JSON.parse("{}");
var value = Reflect.get({ x: 1, y: 2 }, "x");
var first = Atomics.load(foo, 0);
var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });