Search code examples
javascriptextjsextjs4extjs-mvc

Where to add Global variables in ExtJS MVC?


I am wondering where to add global variables for an ExtJS Application. I already looked at some suggestions in stackoverflow that mention that you can add them inside app.js. But, can anyone be more specific? My app.js looks something like this:

Ext.application({

    launch: function() {..}

});

So, where exactly do the variables go? In the launch function? Outside Ext.application?


Solution

  • Declare your own object namespace and add them there:

    Ext.ns('My.Application.Globals');
    
    My.Application.Globals.SomeValue = 5;
    My.Application.Globals.SomeText = 'Hello World!';
    

    However globals are usually frowned upon unless absolutely needed, so try and get around using them if you can.