37 lines
829 B
Plaintext
37 lines
829 B
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,javascript]
|
|
----
|
|
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
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|