javascript中实现继承的几种方式

1、借用构造函数实现继承

function Parent1(){
this.name = "parent1"
}
function Child1(){
Parent1.call(this);
this.type = "child1";
}

缺点:Child1无法继承Parent1的原型对象,并没有真正的实现继承(部分继承)

2、借用原型链实现继承

function Parent2(){
this.name = "parent2";
this.play = [1,2,3];
}
function Child2(){
this.type = "child2";
}
Child2.prototype = new Parent2();

缺点:原型对象的属性是共享的

3、组合式继承

function Parent3(){
this.name = "parent3";
this.play = [1,2,3];
}
function Child3(){
Parent3.call(this);
this.type = "child3";
}
Child3.prototype = Object.create(Parent3.prototype);
Child3.prototype.constructor = Child3

最新文章

  1. mysql 修改密码
  2. SQL优化快速入门
  3. Eclipse web项目引用其它项目时的部署问题
  4. Windows下 maven3.0.4的安装步骤+maven配置本地仓库
  5. Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
  6. 深度剖析C++对象池自动回收技术实现
  7. IIS 发布MVC 提示开启目录浏览
  8. django构建blog--建立数据库部分+admin部分(eclipse+pydev)
  9. DIV+CSS列表式布局(同意图片的应用)
  10. memcached构建集群分析之一
  11. Visifire Chart控件设置 柱状图 条的宽窄
  12. 关于jave在oracle驱动下事务提交与回滚问题
  13. iOS 7用户界面过渡指南
  14. BZOJ 2142: 礼物
  15. Chapter 8: Exceptional Control Flow
  16. 02.将SDK获取到的ECS主机信息入库
  17. XML,HTML,XHTML
  18. Lua rawget rawset newindex 函数定义和例子
  19. 4.27Linux(5)
  20. proxysql 系列 ~ 高可用架构

热门文章

  1. LeetCode Golang 6. Z 字形变换
  2. zabbix监控自身为监控机(server)
  3. laravel报错:MassAssignmentException
  4. sql limit 的用法
  5. 我的Linux系统开始学习的过程
  6. uboot的readme导读
  7. python_函数、局部变量与全局变量
  8. Windows桌面美化
  9. Django REST Framework 序列化和校验 知识点
  10. BlogEngine.NET架构学习:Extension扩展实现