<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>groupInherit</title>
    <script type="text/javascript">
    //声明父类
    function superClass(name){
        this.name = name;
        this.books = ['html','css','js'];
    }
    superClass.prototype.getName = function(){
        console.log(this.name);
    }
    superClass.prototype.getBooks = function(){
        console.log(this.books);
    }
    //声明子类
    function subClass(name,time){
        superClass.call(this,name);//让子this指向父this,后面带的是父类需传入的参数name
        this.time = time;
    }
    subClass.prototype = new superClass();//类式继承
    subClass.prototype.getTime = function(){
        console.log(this.time);
    }
    //测试用例:实例化对象测试
    var test1 = new subClass('js book',2015);
    var test2 = new subClass('css book',2014);
    test1.books.push('php');//test2插入的数据'php'不影响test1

console.log(test1.name);      //'js book'
    console.log(test1.books);   //["html", "css", "js", "php"]
    test1.getName();              //'js book'
    test1.getBooks();           //["html", "css", "js", "php"]
    test1.getTime();            //2015

console.log(test2.name);      //'css book'
    console.log(test2.books);   //["html", "css", "js"]
    test2.getName();              //'css book'
    test2.getBooks();           //["html", "css", "js"]
    test2.getTime();            //2014

//本例已经通过验证,this属性和原型方法均能访问
    </script>
</head>
<body>
    
</body>
</html>

js原生设计模式——2面向对象编程之继承—new+call(this)组合式继承的更多相关文章

  1. js原生设计模式——2面向对象编程之继承—原型继承(类式继承的封装)

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

  2. js原生设计模式——2面向对象编程之继承—多继承

    1.单对象克隆 <!DOCTYPE html><html lang="en"><head>    <meta charset=" ...

  3. js原生设计模式——2面向对象编程之继承—call(this)构造函数式继承

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

  4. js原生设计模式——2面向对象编程之继承—new类式继承

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

  5. js原生设计模式——2面向对象编程之js原生的链式调用

    技巧点:对象方法中返回当前对象就可以链式调用了,即方法中写return this; <!DOCTYPE html><html lang="en"><h ...

  6. js原生设计模式——2面向对象编程之闭包2

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

  7. js原生设计模式——2面向对象编程之闭包1

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

  8. js原生设计模式——7原型模式之new+call(this)组合应用再探讨实例

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

  9. js原生设计模式——12装饰者模式

    1.面向对象模式装饰者 <!DOCTYPE html><html lang="en"><head>    <meta charset=&q ...

随机推荐

  1. (转)多个mapreduce工作相互依赖处理方法完整实例(JobControl)

    多个mapreduce工作相互依赖处理方法完整实例(JobControl) 原文地址:http://mntms.iteye.com/blog/2096456?utm_source=tuicool&am ...

  2. 安卓EditText按钮

    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

  3. mysql查询的cache

    Mysql SQL_NO_CACHE不生效的问题 贾春春 1 票 1224 我想通过SQL_NO_CACHE得知某个query查询速度,但似乎无法实现 例如首次查询: mysql> select ...

  4. 打造最强Windows Server 2012 给你比Windows 8更好的体验

    每一代微软桌面操作系统推出的时候,都会同步推出相应核心的服务器操作系统,稳定性会更强哈 所以改造一下,让它保留兼容和专业的同时又有桌面操作系统的美观和便捷,多好 咳咳,让我们来看看怎么把Server ...

  5. <c:foreach> 标签怎么获取循环次数?

    <c:forEach var="i" begin="1" end="9" varStatus="status"&g ...

  6. android systemUI--Notification 整理

    PendingIntent Intent是一个意图,一个描述了想要启动一个Activity.Broadcast或是Service的意图.它主要持有的信息是它想要启动的组件(Activity.Broad ...

  7. Transport layer and Network layer

    http://stackoverflow.com/questions/13333794/networking-difference-between-transport-layer-and-networ ...

  8. javascript中0.01*2324=23.240000000000002 ?

    js中的乘法运算的小问题 0.01*2324=23.240000000000002 ? , 结果为什么出现这么多小数位呢?

  9. 读 《我为什么放弃Go语言》 有感

    最近又熟悉了下go语言,发现go语言还有许多设计不好的地方,然后又读到了<我为什么放弃Go语言>这篇文章, 对于某些方面,我还是比较认同的. 这篇文章总结了十六点,如下: 1.1 不允许左 ...

  10. Angular2 - Starter - Routes, Route Resolver

    在基于Angualr的SPA中,路由是一个很重要的部分,它帮助我们更方便的实现页面上区域的内容的动态加载,不同tab的切换,同时及时更新浏览器地址栏的URN,使浏览器回退和前进能导航到历史访问的页面. ...