function Animal(){
this.name='pig';
this.sex='men';
};
function People(){
this.name='xiaoming';
this.age=89;
};
//可以覆盖Animal里面的属性
People.prototype = new Animal();
//只能为其增加新属性 不会覆盖
People.prototype.eye= 3;
//可以同时为People增加多个属性 但是遇到和People相同的属性不会覆盖
//People.prototype.name和People.prototype 不能同时使用会导致首先设置的失效
People.prototype={firstname:'xiaoshabi',name:'xiaoshabibbbbbbb'};
var ren=new People();
alert(ren.name+" "+ren.firstname+" "+ren.eye);
js prototype学习
最新推荐文章于 2024-09-17 17:23:28 发布