modularjs
Version:
Library for building events based apps
71 lines (59 loc) • 1.46 kB
JavaScript
var BaseComponent = function(box, mixins){
var self = this;
var container = box;
var mixins = mixins;
this.containerExecute = function(name){
if(container[name] && typeof container[name] == 'function'){
var args = Array.prototype.slice.call(arguments);
args.shift();
return container[name].apply(this, args);
}
return false;
};
this.containerAdd = function(obj, overwrite){
if(overwrite == true){
Object.assign(container, obj);
}
else{
for(propName in obj){
if(typeof container[propName] == "undefined"){
container[propName] = obj[propName];
}
}
}
}
this.containerSet = function(name, value, overwrite){
if(typeof container[name] == 'undefined' || overwrite == true){
container[name] = value;
return true;
}
return false;
};
this.containerGet = function(name){
if(name && typeof container[name] != 'undefined'){
return container[name];
}
else if(!name){
return container;
}
return false;
};
this.containerDelete = function(name){
if(typeof container[name] != 'undefined' ){
delete container[name];
return true;
}
return false;
}
this.mixin = function(name){
if(mixins[name]){
var alias = function(){
var args = Array.prototype.slice.call(arguments);
mixins[name].apply(self, args);
};
return alias;
}
return false;
}
}
module.exports = BaseComponent;