A function call and a constructor call can use the same function but produce different results. Put `new` before the call when you want a new object instance initialized by that function. A constructor function is an ordinary function; how you invoke it makes the difference. section 4.2.3
What happens when you call `new Ninja()`?
- JavaScript creates an object and passes it to `Ninja` as `this`. Assignments such as `this.skulk = function() { return this; }` give the object a method. section 4.2.3
- The new object's prototype is set to `Ninja.prototype`. A method placed there can be called on an instance without being assigned inside the constructor. section 7.2
- A primitive returned by the constructor does not replace the new object. An explicitly returned object does: it becomes the result instead. section 4.2.3
Two instances, one initializer
`function Ninja() { this.skulk = function() { return this; }; }` followed by `var ninja1 = new Ninja(); var ninja2 = new Ninja();` creates two objects. Calling `ninja1.skulk()` returns `ninja1`; calling `ninja2.skulk()` returns `ninja2`. section 4.2.3
Listing 7.2. Creating a new instance with a prototyped method
function Ninja(){} #A
Ninja.prototype.swingSword = function(){ #B
return true; #B
}; #B
const ninja1 = Ninja(); #C
assert(ninja1 === undefined, #C
"No instance of Ninja created."); #C
const ninja2 = new Ninja(); #D
assert(ninja2 && #D
ninja2.swingSword && #D
ninja2.swingSword(), #D
"Instance exists and method is callable." ); #D
Compare `Ninja()` with `new Ninja()`: the ordinary call returns `undefined`, while the constructor call creates an instance that can use a method added to `Ninja.prototype`. section 7.2
Watch the return value when a constructor seems to ignore your initialization. If it explicitly returns another object, that object wins—even if the constructor assigned properties to `this`. Also, `new Function(...)`, which creates a function from strings, is a different use of `new` from invoking your own constructor function. section 4.2.3

