When I use new
to instainciate an instance of a certain class, I got the actual instance. When the constructor function has a return value, the new
sen
If you return an object from a constructor, the result of the new ...
expression will be the object you returned:
function myWackyConstructor() {
return new Date();
}
var d = new myWackyConstructor();
console.log(d);
If you return a primitive, the result will be the constructed object:
function myWackyConstructor() {
this.gotAValue = true;
return 3;
}
var v = new myWackyConstructor();
console.log(v.gotAValue);
Typically, you should not return anything from a constructor:
function myNormalConstructor() {
this.gotAValue = true;
}
var v = new myNormalConstructor();
console.log(v.gotAValue);
The question is, why are you returning the constructor from itself?