在纯JavaScript中实现setTimeout()和setInterval() [英] Implementing setTimeout() and setInterval() in pure JavaScript
问题描述
我有一些支持在浏览器上运行的JavaScript基准代码。但是我想在V8的JavaScript引擎控制台模式下运行它,例如'd8'用于测试目的。
I have some JavaScript benchmark code that is supported to be running on browser. But I would like to run it on console mode of JavaScript engine such as 'd8' in V8 for testing purpose.
我为每个DOM变量编写了空变量和函数和函数(例如 document.getElementById
等)。但我无法完全运行代码,因为浏览器不支持来自V8引擎的 setTimeout()
和 setInterval()
。有没有办法在纯JavaScript代码中实现或简单地模拟这些函数?
I have written empty variables and functions for each DOM variables and functions(e.g. document.getElementById
, etc.). But I cannot fully run the code since setTimeout()
and setInterval()
are supported by browser not from V8 engine. Is there a way to implement or simply emulate those functions in pure JavaScript code?
我感谢任何评论。
推荐答案
你不能只用V8 +一些JS,你必须在某种支持定时器的运行时中嵌入JS引擎。对于V8,例如 zombie.js 。
You can't to that with just V8 + some JS, you have to embbed the JS engine in some kind of runtime that supports timers. For V8 there's zombie.js for instance.
这篇关于在纯JavaScript中实现setTimeout()和setInterval()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!