user27
user27

Reputation: 274

how to define global variable in extjs 3.4

I want to declare a global variable like var i=0; in extjs 3.4. in order to check the maximum occurences of '?' inside keypress listner. How can i do that.

Code:

keypress: function(combo, e) {
            var i = 0;
            var charCode = e.getCharCode();
            if ( e.shiftKey && charCode === 63 ) {
                i = i+1;
                if(i=== 3){
                    alert('max three ?s allowed');
                }
            }
        }

} Here every time i is becoming zero so i want to declare i as global.

Raj

Upvotes: 1

Views: 2291

Answers (2)

ohm
ohm

Reputation: 140

Using Global variable is Generally a bad idea.

If I were you I'd wrap up the variables I needed to share in a singleton.

PHP Code: Ext.define('SaherdData', { singleton: true,

txt: 'myvalue', 
meh: 42 

});

Upvotes: 0

Thiem Nguyen
Thiem Nguyen

Reputation: 6365

If you tend to use MVC structure for your application, simply define them in app.js

Note: To my experience, global variable should be meaningful and uppercase. For example:

var MY_GLOBAL_VARIABLE = some_value;

Upvotes: 1

Related Questions