ExtJS4: Accessing global variables from Ext.Application
extjs, extjs4
Solution
You can also create a singleton:
Ext.define('MyApp.util.Utilities', {
singleton: true,
myGlobal: 1
});
in your app:
Ext.application({
stores: [
...
],
views: [
...
],
autoCreateViewport: true,
name: 'MyApp',
controllers: [
'DefaultController'
],
requires: ['MyApp.util.Utilities'], //Don't forget to require your class
launch: function() {
MyApp.util.Utilities.myGlobal = 2; //variables in singleton are auto static.
}
});
Problem
I want to load some application specific settings and save them as global variables when the application is loaded. I have found how to create and access global variable here. This is how my `app.js` looks like: ``` Ext.application({ stores: [ ... ], views: [ ... ], autoCreateViewport: true, name: 'MyApp', controllers: [ 'DefaultController' ], launch: function() { ... } }); ``` Is it possible to set these variables inside `launch: function()` block? If not, are there any alternatives?