zoukankan      html  css  js  c++  java
  • ECMAScript 实现继承的几种方式

    1. 原形链

      function Father() {

          this.fatherName = "licus";

      }

      function Children() {

        this.chidrenName = "king";

      }

      Children.prototype = new Father();

      

    2.借用构造函数

      function Father() {

        this.fatherName = "licus";

      }

      function Children() {

        Father.call(this);

      }

    3.组合继承

      function Father(name){

        this.name = name;

      }

      Father.prototype.sayName = function(){

        console.log(this.name);

      }

      function Children(name, age) {

        Father.call(this, name);

        this.age = age;

      }

      Children.prototype = new Father();

    4.原型式继承

      function object (o) {

        function Instance() {}

        Instance.prototype = o;

        return new Instance();

      }

    5.寄生式继承

      function object (o) {

        function Instance() {}

        Instance.prototype = o;

        return new Instance();

      }

      function createInstance(o) {

        var clone = object(o);

        clone.Name = "lucis"

        return clone;

      }

    6.寄生组合式继承

      function object(o){

        function F() {}

        F.prototype = o;

        return new F();

      }

      function inherit Prototype(Children, Father){

        var prototype = (Father.prototype);

        prototype.constructor = Children;

        Children.prototype = prototype;

      }

      

  • 相关阅读:
    简单 || 复杂
    命令行参数 && json 协议 && 自定义 error 类型
    Circos安装 (转+总结)
    ggplot2—Pathway富集分析气泡图
    ggplot2绘图
    linux常用命令小结
    生信学习网站
    Perl学习建议(转)
    R作图函数(转)
    Android viewPager+fragment实现滑页效果
  • 原文地址:https://www.cnblogs.com/LionheartCGJ/p/6227339.html
Copyright © 2011-2022 走看看