Enforce the use of new for all builtins, except String, Number, Boolean, Symbol and BigInt ​
💼 This rule is enabled in the ✅ recommended config.
🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
They work the same, but new should be preferred for consistency with other constructors.
Enforces the use of new for following builtins:
ObjectArrayArrayBufferBigInt64ArrayBigUint64ArrayDataViewDateErrorFloat32ArrayFloat64ArrayFunctionInt8ArrayInt16ArrayInt32ArrayMapWeakMapSetWeakSetPromiseRegExpUint8ArrayUint16ArrayUint32ArrayUint8ClampedArraySharedArrayBufferProxyWeakRefFinalizationRegistry
Disallows the use of new for following builtins.
These should not use
newas that would create object wrappers for the primitive values, which is not what you want. However, withoutnewthey can be useful for coercing a value to that type.
This rule is fixable, except new String(), new Number(), and new Boolean(), they return wrapped object.
Fail ​
js
const list = Array(10);js
const now = Date();js
const map = Map([
['foo', 'bar']
]);Pass ​
js
const list = new Array(10);js
const now = new Date();js
const map = new Map([
['foo', 'bar']
]);