- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在检查一些遗留代码,我注意到以下几行:
// Stray timeout
var t = setTimeout('',1);
它有什么作用吗?真的需要吗?
SO 上有以下问题:Why is setTimeout(fn, 0) sometimes useful?
The solution is to "pause" the JavaScript execution to let the rendering threads catch up. And this is the effect that setTimeout() with a timeout of 0 does. It is like a thread/process yield in C. Although it seems to say "run this immediately" it actually gives the browser a chance to finish doing some none-JavaScript things that have been waiting to finish before attending to this new piece of JavaScript.
这解释了在 setTimeout 中执行函数的好处。但是执行一个空字符串怎么样?
最佳答案
setTimeout('',1)
这一行什么都不做。您告诉 JavaScript eval()
字符串 ''
。那什么都不做。
有时这样做很有用,因为它“将代码推到堆栈底部”以在函数(以及浏览器正在执行的任何 UI 更新)完成后运行它。
例如:
setTimeout(function(){
// Work with some DOM elements, after the browser has a second to render them
}, 0);
但我看不到空字符串对任何内容有任何影响。
编辑:在 Google Chrome 中,如果您执行 setTimeout('',1)
,它不会返回任何内容。通常,它会向您返回 timeout_id,因此您可以使用 clearTimeout
取消它。但是,在 Google Chrome 中,setTimeout('',1)
返回 undefined
,这让人相信它甚至没有设置超时,因为你没有给它任何事情要做。所以,是的,它字面上什么都不做。
关于javascript - "Stray timeout"- javascript 中的空超时有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23616307/
这个问题已经有答案了: Compilation error: stray ‘\302’ in program, etc (12 个回答) 已关闭 4 个月前。 我用了Notepad++编写代码,当我尝
这是我的代码 int main() { float avg, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 }; avg = average(age);
这个问题在这里已经有了答案: Getting errors stray ‘\342’ and ‘\200’ and ‘\214’ [duplicate] (4 个答案) 关闭 6 年前。 我正在尝试
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我不知道为什么这个程序会出现这个语法错误。 #include #include #define N 30 int main(void) { char sieve[N], *sp;
问题: 从网上拷贝了一段代码,粘贴到自己写的程序strcat_compare.c中,然后编译gcc -o strcat_compare strcat_compare.c; 出现错误如下: 复制
项目运行良好,运行良好,编译良好。直到一些看似随机的时间,它才停止变好。 目前,我遇到了200个流浪错误: ./new:4: error: stray '\376' in program ./new:
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
这个问题在这里已经有了答案: "Stray '\226' in program" compiler errors [duplicate] (2 个答案) 关闭 7 年前。 theRunners[i]
我正在检查一些遗留代码,我注意到以下几行: // Stray timeout var t = setTimeout('',1); 它有什么作用吗?真的需要吗? SO 上有以下问题:Why is set
我正在使用 xcode 进行一些 C++ 编程,突然收到“Stray/377 in program error” 我认为可能是因为我最近开始使用非 Apple 无线键盘并且我可能输入了某种奇怪的组合键
当我看到这样的东西时,我正在使用嵌入式内核源代码: #define OMAP_SYS_TIMER_INIT(name, clkev_nr, clkev_src, clksrc_nr, clksrc_s
我在编译以下漏洞利用代码时遇到问题: http://downloads.securityfocus.com/vulnerabilities/exploits/59846-1.c 我正在使用 "gcc
自从我学会将 XHTML 页面作为 XML 提供服务以来,我开始注意到一些奇怪的事情:每当我在 Firefox 源代码查看器中查看 XHTML 页面时,DOCTYPE总是被标记为错误。根据我将鼠标悬停
我正在使用 RHEL 6 并尝试使用 SWIG 编译一些代码。 SWIG 文件名为 mySwig.i,看起来像 %module base_module %{ #include "
我正在编写一个程序,但收到以下错误消息: error: stray ‘\344’ in program 这是什么意思? 这是程序: int lotto, zahl, i; double produkt
我在我的程序中遇到了一个我不太明白的问题。代码本身看起来非常好。另外,我觉得这段代码在 Code::Blocks 中有效很奇怪对于 Raspberry Pi,但不在 Code::Blocks 上 CH
我在网站内部页面上运行 W3C 验证器,收到了有关 Stray 开始标记 div 的错误: 错误:偏离开始标记 div。 请帮我编写正确的代码。 我的代码: (function(d, s, id)
我在代码块中编写此程序,但在 int86(0x33,®s,®s); 中出现错误 302。我的程序是 #include #include #include #include void theend();
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我是一名优秀的程序员,十分优秀!