May be a simple questions… How do I access variables in backbone.js view?
initialize: function() { //all init here }
render: function() {//all render here }
printFoo: function(event) {
var printVar = this.changeFoo.changeVar // how do I access changeVar here???
}
changeFoo: function(event) {
var changeVar = $(e.currentTarget).attr('id');
}
how do I access changeVar ?
Short answer, you can’t.
Reason:
changeVaris a private member ofchangeFoo.You could promote
changeVarto become a member of the outer object. In which case,changeVarbecomes accessible toinitialize,render,printFooandchangeFoo.http://jsfiddle.net/Njwdx/