本文介绍了鉴于骨干网接入方式变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以是一个简单的问题...我如何访问变量Backbone.js的看法呢?
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');
}
我怎么做访问changeVar?
how do I access changeVar ?
推荐答案
简短的回答,你不能。
原因: changeVar
是的私有成员 changeFoo
您可以的推动的 changeVar
来成为外部对象的成员。在这种情况下, changeVar
变访问初始化
,渲染
, printFoo
和 changeFoo
。
You could promote changeVar
to become a member of the outer object. In which case, changeVar
becomes accessible to initialize
, render
, printFoo
and changeFoo
.
function ConstructorFunctionName(){
var changeVar = 'foo';
/*this.changeVar = 'foo'; // this can also be used */
this.initialize = function() { //all init here };
this.render = function() { //all render here };
this.printFoo = function(event) {
var printVar = changeVar;
};
this.changeFoo = function(event) {
this.changeVar = $(e.currentTarget).attr('id');
};
}
这篇关于鉴于骨干网接入方式变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!