Reputation: 11
What is the difference between this constructor function:
var Person = function(living, age, gender) {
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function() {return this.gender};
}
and this one:
var Person = function Person(living, age, gender) {
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function() {return this.gender;};
};
Upvotes: 0
Views: 51
Reputation: 1904
Nothing at all, other than the constructor function being "named". For #1, Person.name
would evaluate to an empty string, and for #2, Person.name
would evaluate to "Person"
.
Upvotes: 3
Reputation: 909
The name
property will be set in the function Person(...)
.
You can see this by trying something like
var bar = function eigor(){}
and then seeing what bar.name
is.
Upvotes: -1