单例模式的增强模块
将类或函数类加入到数组中,然后从数组中查找函数名,如果存在即调出调用,
这种模块主要是管理应用程序级的信息和调用
比如你有很多的模块类,就可以加入到这个单例模块中,然后进行管理和调用
let application=function(){
let components=new Array();
components.push(new BaseComponent());
let app=new BaseComponent();
app.getComponentCount=function(){
return components;
};
app.reisterComponent=function(component){
if(typeof new component=="object")
{
components[component.name]=new component;
}
};
app.getObject=function(name)
{
if(Object.keys(components).includes(name))
{
return components[name];
}
}
return app;
}();
function BaseComponent(){}
function Person(){
this.name='nicholas';
this.getName=function(){
return this.name;
};
}
Person.prototype.bind=function(){
console.log('bind');
};
application.reisterComponent(Person);
console.log(application.getComponentCount());
let person=application.getObject('Person');
person.bind();