23 lines
591 B
Plaintext
23 lines
591 B
Plaintext
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
|
|
----
|
|
|