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:

  1. Arrow function is called with the new operator.
  2. Async function is called with the new operator.
  3. Generator function is called with the new operator.
  4. Symbol function is called with the new operator.

Noncompliant Code Example

View with compliant examples side by side
function* 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 side
function* foo() {}
var a = foo();

function bar() {}
new bar();

var b = Symbol();

Version

This rule was introduced in DeepScan 1.0.0-alpha.

Was this documentation helpful?