Singletons of EXTJS

Otherwise known as the module design pattern this pattern allows you to create private JS Variables or methods through the clever use of closures. The singleton is a good pattern to use when you you have a class of static methods, or you have a class that will only be used once. A good candidate for a singleton is the entry point into your application.

MyApp = function(){
var data; data is private and can't be accessed from outside.
return {
init: function(){
// Initialize application here
},

getData: function(){
return data;
}
};
}();
Ext.onReady(MyApp.init, MyApp);
posted @ 2009-08-06 11:40  已注销00021  阅读(156)  评论(0编辑  收藏  举报