我有过
Myitem1.MyFunc();
Myitem2.MyFunc();
function MyFunc(){
if (okToUpdate){
//we weren't here from anywhere within the last 100 milliseconds
}
}不幸的是,okToUpdate变量不会立即更新,因此距离上次调用函数至少需要100毫秒才能获得正确的值。如何使MyFunc延时执行?
发布于 2013-06-20 19:12:24
setTimeout(function(){
Myitem1.MyFunc();
},100)就能达到目的。如果你确切地解释你想要什么,我可以给你确切的时间代码。
发布于 2013-06-20 19:15:14
此代码可能会对您有所帮助
var clrTime=null;
MyFunc(){
clrTime=setTimeout(function(){
if (okToUpdate){
// your code to do
}
},100);
}发布于 2013-06-20 19:22:08
使用回调或承诺将是干净的解决方案。而不是某种使用超时实现的忙碌等待。
https://stackoverflow.com/questions/17212104
复制相似问题