zoukankan      html  css  js  c++  java
  • 前端的设计模式 -- 混合模式

    混合模式

    function Person(name,age){
        this.name = name;
        this.age = age;
    };
    Person.prototype.printName = function(){
        console.log(this.name);
    }
    function Student(name,age){
        继承 Person 的属性
        Person.call(this,name,age);
    }
    function create(prototype){
        function F(){};
        F.prototype = prototype;
        return new F();
    }
    
    // 让Student的原型指向一个对象,该对象的原型指向了Person.prototype,通过这种方式继承 Person 的方法
    Student.prototype = create(Person.prototype);
    Student.prototype.printAge = function(){
        console.log(this.age);
    }
    var student = new Student('xin',22);
    student.printName(); // "xin"
    

    .

  • 相关阅读:
    数据库 连接(join)
    Linux top
    Game2048
    黑豆白豆问题
    1000个苹果10箱
    Jconsole
    八数码 Java实现
    两数之和
    磁盘调度算法
    常见应用网络层次
  • 原文地址:https://www.cnblogs.com/crazycode2/p/11827442.html
Copyright © 2011-2022 走看看