Virtually none in this case except that some browsers might not like the second named constructor the way it's written there. In fact they're both "named" (via being assigned to a variable name). The first one is PersonT1, the second is named PersonT2. The PersonT2 syntax is redundant though. It could be simply:
Code:
function PersonT2(name, age, gender){
this.name = name;
this.age = age;
this.gender = gender;
this.getGender = function(){
return this.gender;
};
}
And that's the usual syntax for declaring a constructor function.
A truly unnamed constructor would look like so:
Code:
var userX = new (function(name, age, gender){
this.name = name;
this.age = age;
this.gender = gender;
this.getGender = function(){
return this.gender;
};
})("Sally", 35, "female");
console.log(userX.getGender()); // gives: female
Bookmarks