simple-class-utils
v0.3.0
Published
Simple class utilities for ECMAScript 6
Downloads
110
Readme
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]