/*
继承:
儿子继承爸爸;
儿子可以用爸爸的方法和属性;
儿子的改变不影响爸爸;
*/
// 构造函数 == 类
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()
面向对象之继承
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 关于类的继承可以理解为:多种类具有类似的属性,为减少代码的重复率,将一些属性抽象出来,生成一个父类 ,其他类继承这...
- 学习一个新知识的第一步,就是要知道它是什么,然后要知道为什么要用它,最后要知道如何使用它。这篇文章,我们重新认识一...
- 1.什么是继承?继承有什么用处? 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的cla...