All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3686.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Constructor functions, which create new object instances, must only be called with new. Non-constructor functions must not. Mixing these two usages could lead to unexpected results at runtime.

Noncompliant Code Example

function getNum() {
  return 5;
}

function Num(numeric, alphabetic) {
  this.numeric = numeric;
  this.alphabetic = alphabetic;
}

var myFirstNum = getNum();
var my2ndNum = new getNum();  // Noncompliant. An empty object is returned, NOT 5

var myNumObj1 = new Num();
var myNumObj2 = Num();  // Noncompliant. undefined is returned, NOT an object




© 2015 - 2024 Weber Informatics LLC | Privacy Policy