clazzjs

1.0.1 • Public • Published

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({
    // The first argument is a instance method module.
    init: function(){
        // "init" is a special method which is executed in the constructor.
    },
    someMethod: function(){
        // you can define
    },
    someAttribute: ''
},
{
    // The second argument is a static method module.
    someStaticMethod: function(){
    }
});
 
new MyClass().someMethod(); // calling a instance method.
MyClass.someStaticMethod(); // calling a static method.

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')(); // call "someMethod" which is deifined by the super class.
    }
});

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(); // -> 'Hello!'

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.

Readme

Keywords

none

Package Sidebar

Install

npm i clazzjs

Weekly Downloads

0

Version

1.0.1

License

none

Last publish

Collaborators

  • quramy