simple-class-utils

0.3.0 • Public • Published

ECMAScript 6 class utilities

Create an ECMAScript 6 class quickly

Requirements

  • Node >= 6.0.0

Examples

Create class from prototype and constructor

  • Function: createClass

  • Usage: createClass(object prototype, optional function constructor)

var createClass = require('class-utils').createClass;
var MyClass = createClass({
    valueOf() {
        return this.value;
    }
}, function (value) {
    this.value = value;
});
var foo = new MyClass('foo');
console.log(String(foo)); // display 'foo'

Create subclass from super class

  • Function: createClass.super

  • Usage: createClass.super(optional class Super)

var createClass = require('class-utils').createClass;
var SubArray = createClass(Array);
var foo = new SubArray(0, 1, 2, 3, 4, 5);
console.log(foo); // display [0, 1, 2, 3, 4, 5]

/simple-class-utils/

    Package Sidebar

    Install

    npm i simple-class-utils

    Weekly Downloads

    18

    Version

    0.3.0

    License

    MIT

    Last publish

    Collaborators

    • khai96_