1. function Parent(firstname)
  2. {
  3. this.fname=firstname;
  4. this.age=;
  5. this.sayAge=function()
  6. {
  7. console.log(this.age);
  8. }
  9. }
  10. function Child(firstname)
  11. {
  12. this.parent=Parent;
  13. this.parent(firstname);
  14. delete this.parent;
  15. this.saySomeThing=function()
  16. {
  17. console.log(this.fname);
  18. this.sayAge();
  19. }
  20. }
  21. var mychild=new Child("李");
  22. mychild.saySomeThing();
  1. function Parent(firstname)
  2. {
  3. this.fname=firstname;
  4. this.age=;
  5. this.sayAge=function()
  6. {
  7. console.log(this.age);
  8. }
  9. }
  10. function Child(firstname)
  11. {
  12.  
  13. this.saySomeThing=function()
  14. {
  15. console.log(this.fname);
  16. this.sayAge();
  17. }
  18. this.getName=function()
  19. {
  20. return firstname;
  21. }
  22.  
  23. }
  24. var child=new Child("张");
  25. Parent.call(child,child.getName());
  26. child.saySomeThing();
  1. function Parent(firstname)
  2. {
  3. this.fname=firstname;
  4. this.age=;
  5. this.sayAge=function()
  6. {
  7. console.log(this.age);
  8. }
  9. }
  10. function Child(firstname)
  11. {
  12.  
  13. this.saySomeThing=function()
  14. {
  15. console.log(this.fname);
  16. this.sayAge();
  17. }
  18. this.getName=function()
  19. {
  20. return firstname;
  21. }
  22.  
  23. }
  24. var child=new Child("张");
  25. Parent.apply(child,[child.getName()]);
  26. child.saySomeThing();
  1. function Parent()
  2. {
  3.  
  4. this.sayAge=function()
  5. {
  6. console.log(this.age);
  7. }
  8. }
  9. function Child(firstname)
  10. {
  11. this.fname=firstname;
  12. this.age=;
  13. this.saySomeThing=function()
  14. {
  15. console.log(this.fname);
  16. this.sayAge();
  17. }
  18. }
  19.  
  20. Child.prototype=new Parent();
  21. var child=new Child("张");
  22. child.saySomeThing();
  1. function Parent()
  2. {
  3.  
  4. this.sayAge=function()
  5. {
  6. console.log(this.age);
  7. }
  8. }
  9.  
  10. Parent.prototype.sayParent=function()
  11. {
  12. alert("this is parentmethod!!!");
  13. }
  14.  
  15. function Child(firstname)
  16. {
  17. Parent.call(this);
  18. this.fname=firstname;
  19. this.age=;
  20. this.saySomeThing=function()
  21. {
  22. console.log(this.fname);
  23. this.sayAge();
  24. }
  25. }
  26.  
  27. Child.prototype=new Parent();
  28. var child=new Child("张");
  29. child.saySomeThing();
  30. child.sayParent();

js实现继承的五种方式的更多相关文章

  1. js实现继承的5种方式 (笔记)

    js实现继承的5种方式 以下 均为 ES5 的写法: js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承 ...

  2. js 实现继承的6种方式(逐渐优化)

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  3. js 实现继承的几种方式

    //js中实现继承的几种方式 //实现继承首先要有一个父类,先创造一个动物的父类 function Animal(name){ this.name = name; this.shoot = funct ...

  4. 深入浅出js实现继承的7种方式

    给大家介绍7中js继承的方法 有些人认为JavaScript并不是真正的面向对象语言,在经典的面向对象语言中,您可能倾向于定义类对象,然后您可以简单地定义哪些类继承哪些类(参考C++ inherita ...

  5. js实现继承的两种方式

    这是面试时面试官会经常问到问题: js的继承方式大致可分为两种:对象冒充和原型方式: 一.先说对象冒充,又可分为3种:临时属性方式.call().apply(): 1.临时属性方式: 当构造对象son ...

  6. js实现继承的5种方式

    js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承有以下通用的几种方式1.使用对象冒充实现继承(该种实现 ...

  7. JavaScript面向对象(三)——继承与闭包、JS实现继承的三种方式

      前  言 JRedu 在之前的两篇博客中,我们详细探讨了JavaScript OOP中的各种知识点(JS OOP基础与JS 中This指向详解 . 成员属性.静态属性.原型属性与JS原型链).今天 ...

  8. JS实现继承的几种方式

    前言 JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一.那么如何在JS中实现继承呢?让我们拭目以待. JS继承的实现方式 既然要实现继承,那么首先我们得有一个父类,代码如下: // 定义一个 ...

  9. js原型继承的几种方式

    1. 原型链继承 2,构造函数继承(对象冒充继承) 3,组合继承(原型链继承+构造函数继承) 4,原型式继承 5. 寄生组合式继承 一.原型链继承 function Show(){ this.name ...

随机推荐

  1. Linux 下找出超過某些容量的檔案

    找目前所在位置下,所有檔案大小超過3M的file,並列出檔名:大小 find . -type f -size +3M -exec ls -alh {} \; | awk '{print$9 " ...

  2. Hbase1.0 客户端api

    最近在试用Hbase1.0的客户端API,发觉变化还是挺大(以前版本也不熟).到处都是deprecated. 现在应该是这样子: Configuration  conf = HBaseConfigur ...

  3. nodejs高大上的部署方式-PM2

    1.最常用的属nohup了,其实就是在后台执行进程,末尾加个&   [zhoujie@ops-dev ~]$ nohup node /home/zhoujie/ops/app.js & ...

  4. 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  5. Hirbernate第三次试题分析

    解析:HQL语句可以执行T-SQL语句,但执行步骤较复杂,需引入jar包等各种配置. 解析:final修饰的成员变量必须由程序员显式地指定初始值.    static一般用于修饰全局变量 解析:Hib ...

  6. iPhone6分辨率与适配

    iPhone6分辨率与适配 分辨率和像素 经新xcode6模拟器验证(分辨率为pt,像素为真实pixel): iPhone5分辨率320x568,像素640x1136,@2x iPhone6分辨率37 ...

  7. Oracle10g RAC的简单操作

    1.查看OCR位置用户指定的位置会被放置在 /etc/oracle/ocr.loc(Liunx系统) 或 /var/opt/oracle/ocr.loc [oracle@rac4 opt]$ cat ...

  8. C# 截取字符串

    1.根据单个分隔字符用split截取 例如 string st="GT123_1"; string[] sArray=st.split("_"); 即可得到sA ...

  9. Web前端开发基础 第四课(认识CSS样式)

    CSS代码语法 css 样式由选择符和声明组成,而声明又由属性和值组成,如下图所示: 选择符:又称选择器,指明网页中要应用样式规则的元素,如本例中是网页中所有的段(p)的文字将变成蓝色,而其他的元素( ...

  10. loading.gif