Non-constructor function should not be called with the new
operator as a constructor
- CALL_NON_CONSTRUCTOR
- Error
- High
- es6
This rule applies when a non-constructor function is called with the new
operator. In such a case, an exception is thrown.
It can be applied to the following:
- Arrow function is called with the
new
operator. - Async function is called with the
new
operator. - Generator function is called with the
new
operator. Symbol
function is called with thenew
operator.
Noncompliant Code Example
View with compliant examples side by sidefunction* foo() {}
new foo(); // CALL_NON_CONSTRUCTOR alarm
var bar = () => {};
new bar(); // CALL_NON_CONSTRUCTOR alarm
var a = new Symbol(); // CALL_NON_CONSTRUCTOR alarm
Compliant Code Example
View with noncompliant examples side by sidefunction* foo() {}
var a = foo();
function bar() {}
new bar();
var b = Symbol();
Version
This rule was introduced in DeepScan 1.0.0-alpha.