title | layout | rule_type | related_rules | further_reading | |
---|---|---|---|---|---|
no-new-native-nonconstructor |
doc |
problem |
|
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.
This rule is aimed at preventing the accidental calling of certain functions with the new
operator. These functions are:
Symbol
BigInt
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);
}
:::
This rule should not be used in ES3/5 environments.