Javascript - 这些构造函数有什么区别?

Javascript - What is the difference between these constructor functions?

这个构造函数有什么区别:

    var Person = function(living, age, gender) {
        this.living = living;
        this.age = age;
        this.gender = gender;
        this.getGender = function() {return this.gender};
    }

还有这个:

    var Person = function Person(living, age, gender) {
        this.living = living;
        this.age = age;
        this.gender = gender;
        this.getGender = function() {return this.gender;};
    };

什么都没有,除了构造函数是 "named"。对于 #1,Person.name 将计算为空字符串,而对于 #2,Person.name 将计算为 "Person".

name 属性 将设置在 function Person(...).

你可以通过尝试类似

的方式看到这一点
var bar = function eigor(){}

然后看看 bar.name 是什么。