Matt
Matt

Reputation: 11

Javascript - What is the difference between these constructor functions?

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

Answers (2)

Daniel Weiner
Daniel Weiner

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

user49438
user49438

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

Related Questions