clase
JavaScript inheritance implementation.
Thanks to my inspirations: JSFace by Tan Nhu, my.Class by Jie Meng-Gerard, simple inheritance by John Resig, and Underscore.js by Jeremy Ashkenas.
Installation
$ npm install clase
Examples
See test/clase_test.js
.
Create a Class with a constructor
var MyClass = ;var myclass = 'blue';myclassname; // 'blue'
Extend another class
var MyClass2 = ;var myclass2 = 'red';myclass2; // 'red'// __super__ stores the parent prototypeMyClass2__super__;
Extend the constructor or any method calling _super()
var MyClass2 = ;var myclass2 = 'red' 3;myclass2color; // 'red'// __super__ stores the parent prototypemyclass2number = 3;
Create static members with a second objecto when creating the class for the first time
var MyClass = ;MyClassisStatic; // true
Or create static members when extending from another class with the third argument
var MyClass2 = ;MyClass2isStatic; // true
Or create create a class passing three objects:
- The first one will be the parent
- The second will extend the parent
- The third extends static members
var MyClass = ;var myclass = 'red' 3;myclass; // 'color red is #3'
Extend two already created classes into a new one
var MyClass = ;var MyClass2 = ;var MyClass3 = ;var myclass3 = 'red' 3;myclass3; // 'color red is #3'
It also supports extending Backbone objects, for example a Backbone.Model with the nice _super()
method
var MyModel = ;var MyModel2 = ; var mymodel2 = ; mymodel2; // 'red'mymodel2; // 3
Running the Unit Tests
$ npm install
From the command-line
$ npm test
In the browser
Open the test/clase_test.html
License
See LICENSE.txt