Skip to content

Maybe you can try to update the code with Reflect? #6

Description

@rxliuli

Just think that ES6 is not trying to use Reflect?

Modified the code

var aggregation = (base, ...mixins) => {
  /*  create aggregation class  */
  let aggregate = class __Aggregate extends base {
    constructor (...args) {
      /*  call base class constructor  */
      super(...args)

      /*  call mixin's initializer  */
      mixins.forEach(mixin => {
        if (typeof mixin.prototype.initializer === 'function') { mixin.prototype.initializer.apply(this, args) }
      })
    }
  }

  /*  copy properties  */
  let copyProps = (target, source) => {
    Reflect.ownKeys(source)
      .forEach(prop => {
        if (
          prop.match(
            /^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/
          )
        ) { return }
        Reflect.set(
          target,
          prop,
          Reflect.getOwnPropertyDescriptor(source, prop)
        )
      })
  }

  /*  copy all properties of all mixins into aggregation class  */
  mixins.forEach(mixin => {
    copyProps(aggregate.prototype, mixin.prototype)
    copyProps(aggregate, mixin)
  })

  return aggregate
}

Finally, I feel that Reflect is a bit more interesting, nothing more. o((^▽^))o

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions