0.2.4 • Published 9 years ago
es6like-class v0.2.4
es6like-class
Write es6 like classes in es5 with a few more features
Cover some limitations to the current implementation of classes in es6:
- define properties
- use traits
Use
var newClass = require('es6like-class').newClass;
var A = newClass({
constructor: function A(value) {
this.initialized = value;
}
});
var B = newClass({
extends: A,
constructor: function B(value) {
assert.strictEqual(this.constructor, B);
this.bValue = value;
}
});
Class special properties
- abstract: set the class as abstract
- constructor: this is the constructor of the class, like the constructor function in es6 classes
- extends: extends a class from another or from an object
- implements: light checks over expected implementations and warn eventually when something is missing
- prototype
- static: define static properties in the class
- with: an array of traits, objects with properties