25 lines
675 B
Plaintext
25 lines
675 B
Plaintext
By convention, constructor function names should start with an upper case letter as a reminder that they should be called with the ``++new++`` keyword.
|
|
|
|
|
|
A function is considered to be a constructor when it sets all of its arguments as object properties, and returns no value.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
function person (firstName, middleInitial, lastName) { // Noncompliant
|
|
this.firstName = firstName;
|
|
this.middleInitial = middleInitial;
|
|
this.lastName = lastName;
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
function Person (firstName, middleInitial, lastName) {
|
|
this.firstName = firstName;
|
|
this.middleInitial = middleInitial;
|
|
this.lastName = lastName;
|
|
}
|
|
----
|