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;

      }

      

  • 相关阅读:
    C++分数类
    2019 SDN大作业
    个人作业-软工实践总结
    2019 SDN上机第7次作业
    2019 SDN上机第6次作业
    2019 SDN课程阅读作业(2)
    个人作业--软件评测
    2019 SDN上机第5次作业
    2019 SDN上机第4次作业
    2019 SDN第一次阅读作业
  • 原文地址:https://www.cnblogs.com/LionheartCGJ/p/6227339.html
Copyright © 2011-2022 走看看