Based on your application, you can declare your global variable.
Scenario 1: declare inside config
If you intend to use getter / setter methods (for example, change the variable often, then go to the configuration)
Announcement Appconstants
Ext.define('Practice.utilities.AppConstants', { alias:'widget.AppConstants', config:{ mainVarTest : 'mainVarTest', }, testvar: 'Testing value', foo: 'bar', meh: 42, constructor : function(options){ this.initConfig(options); } });
Variable call
var AppConstants = Ext.widget("AppConstants"); console.log(AppConstants.getMainVarTest());
Scenario 2: declare inside a Singleton class
If your application needs a global variable, but it will no longer change inside the application. This class helps to load a constant variable only once. (i.e. you are not going to change the variable). This type is suitable for your application.
Ad
Ext.define('Practice.utilities.AppConstants', { alias:'widget.AppConstants', singleton : true, testvar: 'Testing value', foo: 'bar', meh: 42, });
Call
var AppConstant=Practice.utilities.AppConstants; console.log(AppConstant.foo);
Scenario 3: declare as static
Statics is a static variable (exactly the same as java). The advantage of using a static variable is the lifetime of the variable - an indefinite longer period until it is explicitly deleted.
Ext.define("Practice.utilities.AppConstants",{ statics : { mainVarTest : 'mainVarTest' }, });