gpt4 book ai didi

javascript - Backbone View 访问方法变量

转载 作者:行者123 更新时间:2023-11-30 13:14:49 24 4
gpt4 key购买 nike

可能是一个简单的问题...如何在 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 ?

最佳答案

简短的回答,你不能。

原因:changeVarchangeFoo的私有(private)成员。

您可以提升 changeVar 成为外部对象的成员。在这种情况下,changeVar 可用于 initializerenderprintFoochangeFoo .

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');
};
}

http://jsfiddle.net/Njwdx/

关于javascript - Backbone View 访问方法变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12391512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com