如果需要将作用域保留在嵌套函数中,通常会在嵌套函数中创建一个如下所示的变量:var that = this;
和参考that
。第三学位及以后的会议名称是什么?用于第三个(或更多)嵌套作用域的JS作用域约定
我也遇到过一些使用代理的情况,但从来没有必须在JQuery中传递嵌套代理。有什么特殊的嵌套proxy
小号
正常范围问题在骨干上来了,有一个潜在的(我们仍然可以通过它的工作)不得不去另一个层面下来:
keyPressed: function(keyEvent) {
if(case1 && case2 && case3) {
if(anotherCase) {
.....
}
else if(yetAnotherCase) {
....
var that = this;
window.waitIntervalID = window.setInterval(function() {
if(that.waitCount == 2) {
that.isWaiting = false;
that.waitCount = 0;
that.mainCounter = 0;
that.isRecording = true;
for(var i = 0; i < that.signature; i++) {
that.beatArray[i] = 0;
}
window.tapIntervalID = window.setInterval(function() {
that.count = that.mainCounter + 1;
that.mainCounterTime = new Date().getTime();
that.mainCounter = (that.mainCounter + 1) % that.signature;
}, that.average);
that.isTapping = false;
that.countIn = 1;
var bpm = 1000/that.average * 60;
that.set('tempo', bpm);
window.clearInterval(waitIntervalID);
}
that.waitCount++;
}, this.average);
this.countIn++;
}
}
},
代理范围:
// add click handler to this beat
$('#beat'+this.model.cid).click($.proxy(this.toggle, this));
return this;
贵国是否能说明为什么/如何你想改变的变量名的例子在不同的范围? – 2013-04-28 17:19:43
@MattKantor发布 – 2013-04-29 02:08:39