Merge one or ES6 classes before extending
 
Go to file
Kebler Network System Administrator c9fe5e562a move to local eslint and linting for es2021 2021-05-13 15:39:46 -07:00
src 1.0.3 drop using Reflect, add event emitter to test suite 2020-02-20 22:41:12 -08:00
test 1.1.0 2021-04-24 19:24:12 -07:00
.eslintrc.yml move to local eslint and linting for es2021 2021-05-13 15:39:46 -07:00
.gitignore 1.0.3 drop using Reflect, add event emitter to test suite 2020-02-20 22:41:12 -08:00
.npmignore refactor from aggregation repo 2020-02-20 21:34:20 -08:00
README.md 1.1.0 2021-04-24 19:24:12 -07:00
package.json move to local eslint and linting for es2021 2021-05-13 15:39:46 -07:00

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/)