混成模式 自定义类型

////混成模式
//实例属性--构造函数模式
//定义方法和共享的属性--原型模式
function Person(name,age,job){
this.name = name;
this.age = age;
this.job = job;
this.friends = ["Shelby","Court"];
}

Person.prototype = {
constructor : Person,
sayName : function(){
alert(this.name);
}
}

var person1 = new Person("Nicholas",29,"Software Engineer");
var person2 = new Person("Greg",27,"Doctor");

person1.friends.push("Van");
//person1.sayName();
//person2.sayName();
//alert(person1.friends);
//alert(person2.friends);
//alert(person1.friends === person2.friends);
//alert(person1.sayName === person2.sayName);

猜你喜欢

转载自kelvinqxlq.iteye.com/blog/2322227