/*
继承:
儿子继承爸爸;
儿子可以用爸爸的方法和属性;
儿子的改变不影响爸爸;
*/
// 构造函数 == 类
function Person( name , age , marry , sex ){
this.name = name;
this.age = age;
this.marry = marry;
this.sex = sex;
};
Person.prototype.showName = function(){
console.log( this.name+'is walking' );
};
Person.prototype.yy = function(){
console.log( this.name+'is YY' );
};
// 通过继承创造一个子类
function PersonChild( pArr , weight ){
Person.apply( this , pArr );
this.weight = weight;
};
//PersonChild.prototype = Person.prototype;
PersonChild.prototype = Object.create(Person.prototype)
PersonChild.prototype.showAge = function(){
alert( this.age );
};
var oP = new PersonChild( ['青青' , '18' , false , 1] , 60 );
oP.showName()
oP.yy()
oP.showAge()
网友评论