Is it possible to use global variable in backbone.js view?
backbone.js
Solution
You can easily store variables in at least 3 different scopes:
- Regular instance variables unique to each view instance
- these can be stored as properties on the view's `this` object
- Example: `this.selectedItem = this.$el.find('.selected');`
- Class-level variables shared by all instances of the view
- these can be stored on the View class's constructor function
- Example: `TodoView.counter = 0;` (put that after your entire `.extend` invocation)
- True global variables (yes, these are bad, but since you asked)
- you can leak these by omitting `var` or just explicitly assign to the `window` object
- Example: `window.appLaunchTime = new Date()`
Problem
Is it possible to use global variable in backbone.js view ? exmpl: ``` var TodoView = Backbone.View.extend({ counter: null ; // is this possible ? initialize: function(){ this.render(); }, render: function(){ } }); ```