Cla6.js
Provides a class factory with additional functionality, like mixins
and plugins
. Although originally designed for use with Node.js and installable via npm install cla6
,
it can also be used directly in the browser.
Cla6 is also installable via:
- bower:
bower install cla6
Basic Example
var Cla6 = ; var Parent = ; var Child = ; child = ; // parent constructorchild; // parent method, child methodchildaccessor = childaccessor; // child getter, child setter
Why Use It
- Easy to use
- Easy to read
- Highliy compatible
- Defines classes THE RIGHT WAY
Unlike classic class definition, Cla6 defines unenumerable prototype properties:
// Classic class definition { thisfoo = 'foo'; thisbar = 'bar';} Klassprototypeconstructor = Klass; Klassprototype { return 'baz';}; var instance = ; // prints foo, bar, bazfor var k in instance console; // Cla6 class definition var Klass = ; var instance = ; // prints foo, barfor var k in instance console;
Mixins
Each class created by Cla6 can be extended using a mixin. Mixins can be applied at class creation or during run time.
var mixin1 = { console; }; var mixin2 = { console; }; var mixin3 = { console; }; var Klass = ; Klass; var obj = ; // klassobj; // mixin1obj; // mixin2obj; // mixin3
Plugins
A plugin is a module which adds functionality to Cla6 and can be loaded dynamcally. Multipile plugins can be applied and will be called by their order of use.
Note, each plugin will affect the arguments for the next plugin in the plugins chain.
Cla6;
The official plugins currently available are:
Building a plugin
A basic plugin stracture should look like so:
var { // initializer logic}; var { // manipulator logic}; moduleexports = initialize: initialize manipulate: manipulate;
initialize
- An optional initializer function which will be called with Cla6 instance once the plugin is used.manipulate
- A required manipulator function which will be called every time before a class gets created with its descriptors and Parent class.
Download
The source is available for download from
GitHub.
Alternatively, you can install using Node Package Manager (npm
):
npm install cla6