Is there a standard design pattern for ExtJS
We use ExtJS 3.x pretty heavily within our flagship application. Our application's admin area is split into the different modules 开发者_如何学编程that we offer. Each module, and subsequently each page for the different CRUD actions of the module have their own .js file to handle the functionality.
When we started, we were just throwing all of our code into Ext.onReady()
and not really worrying about the global namespace (hey... we never really thought of ourselves as javascript developers). After getting the hang of ExtJS, I moved to using the singleton pattern and calling the init method from Ext.onReady()
like so.
var newModule = {
propertyOne: 'asfd',
propertyTwo: 'asdf',
init: function() {
// set up
}
};
Ext.onReady(function() {
newModule.init();
});
Is this a correct use of the javascript singleton pattern and are there any patterns that fit ExtJS better than singleton, like say maybe the Module Pattern?
I've been using this guide as a starting point to learning design patterns in Javascript.
We eventually decided to upgrade to ExtJS and it seems with the new MVC architecture in place the best way to design your ExtJS software is using Ext.application()
You can read about it here.
You can look here for example of creating own modules, file Module.js. We used this pattern for our own application and hadn't problem with it.
Ext.app.Module = function(config){
Ext.apply(this, config);
Ext.app.Module.superclass.constructor.call(this);
this.init();
}
Ext.extend(Ext.app.Module, Ext.util.Observable, {
init : Ext.emptyFn
});
精彩评论