Skip to content

noGlobalObjectCalls (since v1.0.0)

Diagnostic Category: lint/correctness/noGlobalObjectCalls

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();
correctness/noGlobalObjectCalls.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Math is not a function.
  
  > 1 │ var math = Math();
              ^^^^
    2 │ 
  
var newMath = new Math();
correctness/noGlobalObjectCalls.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Math is not a function.
  
  > 1 │ var newMath = new Math();
                     ^^^^
    2 │ 
  
var json = JSON();
correctness/noGlobalObjectCalls.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Json is not a function.
  
  > 1 │ var json = JSON();
              ^^^^
    2 │ 
  
var newJSON = new JSON();
correctness/noGlobalObjectCalls.js:1:19 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Json is not a function.
  
  > 1 │ var newJSON = new JSON();
                     ^^^^
    2 │ 
  
var reflect = Reflect();
correctness/noGlobalObjectCalls.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Reflect is not a function.
  
  > 1 │ var reflect = Reflect();
                 ^^^^^^^
    2 │ 
  
var newReflect = new Reflect();
correctness/noGlobalObjectCalls.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Reflect is not a function.
  
  > 1 │ var newReflect = new Reflect();
                        ^^^^^^^
    2 │ 
  
var atomics = Atomics();
correctness/noGlobalObjectCalls.js:1:15 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Atomics is not a function.
  
  > 1 │ var atomics = Atomics();
                 ^^^^^^^
    2 │ 
  
var newAtomics = new Atomics();
correctness/noGlobalObjectCalls.js:1:22 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Atomics is not a function.
  
  > 1 │ var newAtomics = new Atomics();
                        ^^^^^^^
    2 │ 
  
var intl = Intl();
correctness/noGlobalObjectCalls.js:1:12 lint/correctness/noGlobalObjectCalls ━━━━━━━━━━━━━━━━━━━━━━━

   Intl is not a function.
  
  > 1 │ var intl = Intl();
              ^^^^
    2 │ 
  
var newIntl = new Intl();
correctness/noGlobalObjectCalls.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" });