Arale
This is a fork of arale.class and arale.events. The core of arale projects.
The Class and Events of Arale is very easy to use, and stable now. Test cases with 97% coverage, and you don't have to worry about the 3% left.
Class
Read it in Chinese at Arale.Class.
create
Class.create([parent], [properties])
create a new class:
/* pig.js */var Class = Class; var Pig = Class; moduleexports = Pig;
extend
Every class created by Class.create
has an extend
method:
/* red-pig.js */var Pig = ; var RedPig = Pig; moduleexports = RedPig;
implement
You can also mixin other classes:
/* flyable.js */exports { console;};
/* flyable-red-pig.js */var RedPig = ;var Flyable = ; var FlyableRedPig = RedPig; moduleexports = FlyableRedPig;
The other way of mixin:
/* flyable-red-pig-extension.js */var FlyableRedPig = ; FlyableRedPig;
Class
Transfrom a function to class:
{}Animalprototype {}; var Dog = ;
Events
Read it in Chinese at Arale.Events.
How to
There are two ways of implementing events:
var Events = Events; var object = ;object; object;
The other way:
var Events = Events; {}Events; Dogprototype { this;}; var dog = ;dog; dog;
on
object.on(event, callback, [context])
You can pass a context to change the this.
post;
There is an all
event:
proxy;
off
object.off([event], [callback], [context])
// remove the onChange callback of change eventobject; // remove all callbacks of change eventobject; // remove all onChange callbacks of every eventobject; // remove all events for the contextobject; // remove all events of the objectobject;
trigger
object.trigger(event, [*args])
var obj = ; obj; // equals:obj;