创建对象构造器

//例子

function person(firstname,lastname,age,eyecolor){
  this.firstname=firstname;
  this.lastname=lastname;
  this.age=age;
  this.eyecolor=eyecolor;

  //在构造器函数内部定义对象的方法:

  this.changeName=changeName;
  function changeName(name){
    this.firstname=name;
  }

}

//一旦您有了对象构造器,就可以创建新的对象实例,就像这样:

var myFather=new person("John","Doe",50,"blue");
var myMother=new person("Sally","Rally",48,"green");

//修改firstname值

person.changeName("dog")

posted @ 2018-07-31 11:00  瞎几把乱记  阅读(201)  评论(0编辑  收藏  举报