![](/img/trans.png)
[英]What is the difference between (function(global){}(this), constructor functions, and classes in 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;};
};
除了构造函数被“命名”之外,什么都没有。 对于#1, Person.name
将评估为空字符串,对于#2, Person.name
将评估为"Person"
。
name
属性将在function Person(...)
。
您可以尝试以下方法来查看
var bar = function eigor(){}
然后查看什么是bar.name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.