Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.05 KB

no-extra-new.md

File metadata and controls

52 lines (40 loc) · 1.05 KB

no-extra-new

The rule no-extra-new disallows unnecessary usages of the the new syntax.

The following built-in constructors can be called equally with or without new syntax:

  • AggregateError (since ECMAScript 2021)
  • Array
  • Error
  • EvalError
  • Function
  • Object
  • RangeError
  • ReferenceError
  • RegExp
  • SyntaxError
  • TypeError
  • URIError

Examples

Examples of incorrect code for this rule

/* eslint @origin-1/no-extra-new: "error" */

var array = new Array(42);
var fn = new Function;
var obj = new Object('foo');
var regExp = new RegExp('\\d', 'g');
throw new TypeError();

Examples of correct code for this rule

/* eslint @origin-1/no-extra-new: "error" */

var array = Array(42);
var fn = Function();
var obj = Object('foo');
var regExp = RegExp('\\d', 'g');
throw TypeError();

function throwNew(Error)
{
    throw new Error(); // New expressions with a variable as callee are allowed.
}

Superseded core ESLint rules