Merge one or ES6 classes before extending
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Kebler Network System Administrator c9fe5e562a move to local eslint and linting for es2021 1 year ago
src 1.0.3 drop using Reflect, add event emitter to test suite 3 years ago
test 1.1.0 1 year ago
.eslintrc.yml move to local eslint and linting for es2021 1 year ago
.gitignore 1.0.3 drop using Reflect, add event emitter to test suite 3 years ago
.npmignore refactor from aggregation repo 3 years ago
README.md 1.1.0 1 year ago
package.json move to local eslint and linting for es2021 1 year ago

README.md

Class Merge

Merge of additional (mixin) Classes into an primary (base) class

About

Class Merge is a very small JavaScript library for Node.js environments, providing just a single function for use in ECMAScript 6 class inheritance. It aggregates/merges a base class and one or more mixin classes into an aggregate class, which then is usually subsequently used as the base class for another class.

Installation

$ npm install @uci-utils/class-merge

Usage

ECMAScript 6

requires using -r esm

import merge from '@uci-utils/class-merge'

class Colored {
    initializer ()     { this._color = "white" }
    get color ()       { return this._color }
    set color (v)      { this._color = v }
}

class ZCoord {
    initializer ()     { this._z = 0 }
    get z ()           { return this._z }
    set z (v)          { this._z = v }
}

class Shape {
    constructor (x, y) { this._x = x; this._y = y }
    get x ()           { return this._x }
    set x (v)          { this._x = v }
    get y ()           { return this._y }
    set y (v)          { this._y = v }
}

class Rectangle extends merge(Shape, Colored, ZCoord) {}

var rect = new Rectangle(7, 42)
rect.z     = 1000
rect.color = "red"


Credits
-------

thx to aggregation 2015-2019  by Dr. Ralf S. Engelschall (http://engelschall.com/)