继承的方式一共有三种:

一、原型继承

通过prototype   来实现继承。

   function Person(name,age) {
this.name=name;
this.age=age;
} Person.prototype.sayHello=function(){
alert (''使用原型得到Name:'' + this.name); } var per = new Person("马小倩",21);
per.sayHello();//输出:使用原型得到Name:马小倩 function Student(){} Student.prototype=new Person("洪如彤",21); //实现原型继承 var stu = new Student(); Student.prototype.grade=5; Student.prototype.intr=function(){
alert(this.grade);
} stu.sayHello();//输出:使用原型得到Name:洪如彤
stu.intr();//输出:5

二、构造函数实现继承

 function Person(name,age) {
this.name=name;
this.age=age;
} Person.prototype.sayHello=function(){
alert (''使用原型得到Name:'' + this.name); } var per = new Person("马小倩",21);
per.sayHello();//输出:使用原型得到Name:马小倩

三、  通过call、apply  实现继承

最新文章

  1. 从零开始山寨Caffe·拾:IO系统(三)
  2. Linux-深入理解Socket异常
  3. phonegap(cordova)环境配置
  4. 内存管理tcmalloc
  5. EasyUI篇のDataGrid
  6. o2o
  7. easyui datagrid shift 多选
  8. Eclipse中代码提示框的背景色修改
  9. Java中正则表达式去除html标签
  10. okHttp基础用法
  11. Vue之Vuex
  12. jsonp跨域再谈
  13. (Alpha)个人总结
  14. js onmouseover与onmouseout用法
  15. 本人在CSDN上的技术博客访问量突破了10万次,特此截图留念
  16. jmeter 安装
  17. Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)
  18. Linux Cluster 基础之LVS调度算法与集群类型
  19. java struts2入门学习---文件下载的二种方式
  20. HDFS Users Guide

热门文章

  1. Moya 与 RxSwift 使用
  2. Log4j2同步异步性能比较以及教程和问题(坑)汇总
  3. CODEVS 1245 最小的N个和 堆+排序
  4. Spring 详解(三)------- SpringMVC拦截器使用
  5. JDBC 数据库连接 Java操作数据库 jdbc快速入门
  6. IO流的文件复制
  7. SystemTap使用技巧 1 - 4 非常重要
  8. android应用开发之View的大小计量单位(px、dpi、dp、dip、sp)
  9. java cocurrent并发包
  10. C# UserControl 判断是否是设计模式中