如果您需要在嵌套函数中保留范围,通常会创建一个变量,即 this 像这样:var that = this;
并引用that
在嵌套函数中引用。3 级及以上学位的约定名称是什么?
我也遇到过一些使用代理的情况,但从来没有在 JQuery 中传递嵌套代理。proxy
嵌套s有什么特别的吗
骨干中出现了常规范围问题,有可能(我们仍在努力解决它)必须再往下走:
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;