function Parent(name,sex){
this.name = name;
this.sex = sex;
this.sayName = function(){
console.log(this.name+' : '+this.sex);
}
}
Object.prototype.method = function(obj){
for (var attr in obj){
this[attr] = obj[attr];
}
}
function Son(age){
this.age = age;
this.show = function(){
console.log(this.name+' : '+this.sex+' : '+this.age);
}
}
var p1 = new Parent('zhangsan','男');
var p2 = new Son(23);
p2.method(p1);
p2.show();
因为给原型链的的顶端添加方法,所以所有的对象都会添加此属性和方法