Skip to content

Latest commit

 

History

History
74 lines (50 loc) · 1.25 KB

no-new-native-nonconstructor.md

File metadata and controls

74 lines (50 loc) · 1.25 KB
title layout rule_type related_rules further_reading
no-new-native-nonconstructor
doc
problem
no-new-symbol

Certain functions are not intended to be used with the new operator, but to be called as a function.

var foo = new Symbol("foo");
var bar = new BigInt(9007199254740991)

These throw a TypeError exception.

Rule Details

This rule is aimed at preventing the accidental calling of certain functions with the new operator. These functions are:

  • Symbol
  • BigInt

Examples

Examples of incorrect code for this rule:

::: incorrect

/*eslint no-new-native-nonconstructor: "error"*/
/*eslint-env es2022*/

var foo = new Symbol('foo');
var bar = new BigInt(9007199254740991);

:::

Examples of correct code for this rule:

::: correct

/*eslint no-new-symbol: "error"*/
/*eslint-env es2022*/

var foo = Symbol('foo');
var bar = BigInt(9007199254740991);

// Ignores shadowed Symbol.
function baz(Symbol) {
    const qux = new Symbol("baz");
}
function quux(BigInt) {
    const corge = new BigInt(9007199254740991);
}

:::

When Not To Use It

This rule should not be used in ES3/5 environments.