Include syntactic sugar to help the development of out interface.
Function.prototype.method = function (name, FN) {
This.prototype[name] = fn;
return this;
};
(function () {
function _$ (ELS) {
//...
}
/*
Events
* Addevent
* GetEvent
*/
_$.method (' addevent ', function (type, fn) {
//...
}). Method (' GetEvent ', function (e) {
//...
/*
Dom
* AddClass
* Removeclass
* Replaceclass
* Hasclass
* GetStyle
* SetStyle
*/
). Method (' AddClass ', function (className) {
//...
). Method (' Removeclass ', function (className) {
//...
). Method (' Replaceclass ', function (Olcclass, newclass) {
//...
). Method (' Hasclass ', function (className) {
//...
). Method (' GetStyle ', function (prop) {
//...
). Method (' SetStyle ', function (prop, Val) {
//...
/*
Ajax
* load. Fetches an HTML fragment from a URL and inserts it to an element.
*/
}. Method (' Load ', function (URL, method) {
//...
});
window.$ = function () {
return new _$ (arguments);
};
})();
window.API = window.API || function() {
var name = 'Hello world';
//Privileged mutator method.
this.setName = function(newName){
name = newName;
return this;
};
this.getName = function(callback){
callback.call(this, name);
return this;
};
};
var api = new API;
api.getName(console.log).setName('Meow').getName(console.log);