【Javascript对象】Person、prototype

133 阅读1分钟
Person被称为"构造器",相当于有很多"房间"的"宾馆"

function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}


Father是Person的实例,new代表开放、营业,而Father则是执行人

var Father = new Person("John", "Doe", 50, "blue");


如何向"构造器"添加"新属性"?想让"宾馆"增加"房间,请需找老板批准,而"构造器"的老板,则是prototype

Person.prototype.nationality = "English";