Non-constructor function should not be called with new operator as a constructor

  • CALL_NON_CONSTRUCTOR
  • Error
  • High
  • es6

This rule applies when a non-constructor function is called with new operator. In such a case, an exception is thrown.

It can be applied to the following:

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

Noncompliant Code Example

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

function * foo() {}
var a = foo();

function bar() {}
new bar();

var b = Symbol();

Version

This rule was introduced in DeepScan 1.0.0-alpha.