2

I need to have a set of Global Variables in a class, and need to access it from other classes. I have the following problems, can someone help me ?

1.) What type of class should i add ? is it a View ? Can someone show an example ? 2.) How can i set values to the variables in this class from my Controller and View classes ? 3.) How can i retrieve the values of these variables from this class (global variable class) ?

note: I know how to add it to the app.js and write/read from other classes. But i want to have a separate class for global variables.

Sharon Watinsan
  • 9,620
  • 31
  • 96
  • 140

1 Answers1

9

Add them as statics in a new class:

Ext.define('MyApp.util.Utilities', {
    statics: {
        myGlobal: 1
    }
});

At which point you load the class up and from anywhere in the app you can write MyApp.util.Utilities.myGlobal = 5.

This is an extension of my answer here to a similar problem: Where should I define global functions in ExtJS 4 MVC?

Community
  • 1
  • 1
David Kanarek
  • 12,611
  • 5
  • 45
  • 62