with to attach lightweight traits / mixins enabling composition behind optional initializers per each mixin. Compatible with universal-mixin since version
Features Example
This is an example of what's possible:
var Engineer = Class({ extends: Person, with: [ eventEmitter, growingEachYear, carrierPath ], implements: [ iWorker ], static: { SOFTWARE: 0, CONSTRUCTIONS: 1 }, constructor: function (name, age, type) { this.super(name, age); this.type = type; }});var me = new Engineer( 'Mr. Andrea Giammarchi', 36, Engineer.SOFTWARE
ES6 Ready
Using Babel it is possible to make your code directly compatible down to ES5 or even ES3 without loosing the ability to debug in every platform without needing source-map. What you see is basically what you get.
// how you would write in native ES6class B extends A { method(x, y) { return super.method(x, y); } get value() { return super.value; } set value(value) { super.value = value; }}// how you would write in es-classvar B = Class({ extends: A, method(x, y) { return this.super(x, y); }, get value() { return this.super
A simple call to babel --whitelist=es6.arrowFunctions,es6.properties.shorthand f.js and the output will be way cleaner than any automation produced by the same transpiler.
Your output will be more readable and also probably faster at execution time.
ES7 Ready
Looking at the future, grouped static properties and lightweight traits are also in, giving the ability to compose classes through eventual traits initialization without being on the way after class definition.
var wheels = { init: function () { if (this instanceof Car) { this.frontWheels = 2; this.rearWheels = 2; } else { this.frontWheels = 1; this.rearWheels = this instanceof Tricycle ? 2 : 1; } }, turn: function (where) { console.log('turning ' + where); }
Which File ?
as global to include inline or before any other file that uses classes