gpt4 book ai didi

javascript - window.setInterval() 的 dojo.hitch() 范围

转载 作者:行者123 更新时间:2023-11-29 09:55:39 25 4
gpt4 key购买 nike

我正在尝试使用 dojo fadeIn/Out 产生闪烁效果。

下面的代码片段是在小部件类的声明中定义的:

 _startHighlightEffect : function() {
var blinkInterval = 5000; //Scope here is that of the parent widget
window.setInterval ( function() {
dojo.fadeOut(
{
node: this._headerDiv.domNode,
onEnd: function() {
dojo.fadeIn({node: this._headerDiv.domNode},3000).play();
}
},3000).play();
}, blinkInterval);
},

_highlightEffect : function() {
this.func = dojo.hitch(this,this._startHighlightEffect);
this.func();
}

我面临的问题是它说,“this._headerDiv is undefined”。在使用 firebug 检查时,this._headerDiv 的范围是 Window 而不是父窗口部件。

请帮助我了解我在这里缺少什么。

最佳答案

@jbabey 描述的内容会起作用,但就 dojo.hitch 而言,您在错误的函数上使用了它。您需要连接传递给 setInterval 的函数。

_startHighlightEffect : function() {
var blinkInterval = 5000; //Scope here is that of the parent widget

// hitch the function that will be executed by the setInterval call *********
window.setInterval (dojo.hitch(this, function() {
dojo.fadeOut(
{
node: this._headerDiv.domNode,
onEnd: dojo.hitch(this, function() {
dojo.fadeIn(
{node: this._headerDiv.domNode},3000).play();
})
},3000).play();
}, blinkInterval));
},

_highlightEffect : function() {
this._startHighlightEffect();
}

关于javascript - window.setInterval() 的 dojo.hitch() 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12265661/

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