Clazz.js
Clazz.js is a simple JavaScript class providing liblary.
Getting Started
using in webapp
Download js file from here.
<script type="text/javascript" src="clazz.min.js"></script>
var MyClass = new Clazz({
init: function(message){
this.message = message;
},
say: function(){
console.log(this.message);
}
});
var myClass = new MyClass('I am an instance of MyClass.');
myClass.say();
using in node.js app
Install the module with: npm install clazzjs
var Clazz = require('clazz');
var MyClass = new Clazz({
init: function(message){
this.message = message;
},
say: function(){
console.log(this.message);
}
});
var myClass = new MyClass('I am an instance of MyClass.');
myClass.say();
Documentation
Create a Class
var MyClass = new Clazz({
init: function(){
},
someMethod: function(){
},
someAttribute: ''
},
{
someStaticMethod: function(){
}
});
new MyClass().someMethod();
MyClass.someStaticMethod();
Inheritance
Clazz.js supports Inheritance. Use "extend" method to create a sub class.
In subclass method, you can use access super method by "_dl" property.
The "_dl" property returns a function to delegate super method.
var SubClass = MyClass.extend({
someMethod: function(){
this._dl('someMethod')();
}
});
Mix in
Using "mixin" method, you can import an external module to your class.
var module = {
action: function(){
console.log(this.message);
};
};
var MyClass = new Clazz({
init:function(message){
this.message = message;
}
}).mixin(module);
new MyClass('Hello!').action();
Examples
(Coming soon)
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
(Nothing yet)
License
Copyright (c) 2013 quramy. Licensed under the MIT license.