zoukankan      html  css  js  c++  java
  • es6使用mixmin实现多继承

    function mix(...mixins) {
      class Mix {
        constructor() {
          for (let mixin of mixins) {
            copyProperties(this, new mixin()); // 拷贝实例属性
          }
        }
      }
    
      for (let mixin of mixins) {
        copyProperties(Mix, mixin); // 拷贝静态属性
        copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性
      }
    
      return Mix;
    }
    
    function copyProperties(target, source) {
      for (let key of Reflect.ownKeys(source)) {
        if ( key !== 'constructor'
          && key !== 'prototype'
          && key !== 'name'
        ) {
          let desc = Object.getOwnPropertyDescriptor(source, key);
          Object.defineProperty(target, key, desc);
        }
      }
    }
    

      

    class A mix(modelA,modelB){
    
    }
    

      

  • 相关阅读:
    c copy
    IfcVertexLoop
    qt windeployqt 日志
    IfcPolyLoop
    IfcEdgeLoop
    IfcLoop
    QTableWidget
    QList删除元素
    matlab X的负次方函数绘制2
    matlab X的负次方函数绘制1
  • 原文地址:https://www.cnblogs.com/mmykdbc/p/13680471.html
Copyright © 2011-2022 走看看