Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Global variables in EXT JS

In java and C++ we could store a variable globally and access its value from any where in the project. Say, i am inside a class called Residence and i am saving the residenceNumber which is a INT to a global variable called houseNumberGlobalVariable.

Now, i could access houseNumberGlobalVariable from any class in the project. In a similar fashion, is there a Global variable in EXTJS that i could use.

I need to set a value from one class and access it from another. What is the equivalent in EXT JS. I don't think there's a global variable concept in EXTJS, but what is the equivalent in it ?

like image 588
Sharon Watinsan Avatar asked Jul 05 '12 11:07

Sharon Watinsan


1 Answers

Create a special class and put all your global variables there.

Ext.define('MyApp.global.Vars', {
    singleton: true,
    ....   
    houseNumberGlobalVariable: undefined

});

This way if you need access for it anywhere in the code just use MyApp.global.Vars.houseNumberGlobalVariable

like image 199
sha Avatar answered Sep 27 '22 17:09

sha