I've installed V8 standalone and execute javascript code like this: ./d8 source.js
. When I use setTimeout I receive ReferenceError: setTimeout is not defined
. Is this how it's supposed to be? Is it possible to somehow include this function?
I've installed V8 standalone and execute javascript code like this: ./d8 source.js
. When I use setTimeout I receive ReferenceError: setTimeout is not defined
. Is this how it's supposed to be? Is it possible to somehow include this function?
2 Answers
Reset to default 13setTimeout
is not part of ECMA-262, it's implemented by the browsers. However, if you install Node.js (which is V8 + extras) you will get a command line setTimeout
.
For what it's worth, V8 has its own setTimeout
now (~7.5 years later), in the shell it provides. But it only takes one parameter (the function to call) and schedules it to be called once the current job is completed, roughly as though you'd passed 0
as the second parameter to the more familiar form of setTiemout
provided by browsers and Node.js.
So given example.js
:
console.log("a");
setTimeout(() => {
console.log("c");
}, 5000);
console.log("b");
then
$ v8 example.js
outputs
a b c
...with no appreciable delay between b
and c
.
(That example uses the v8
command installed by jsvu, which is at least one way you run code directly in V8. I think d8
got subsumed...)
window
object, from whichsetTimeout
would normally be called. – Jared Farrish Commented Sep 8, 2012 at 23:17