I have built spidermonkey on mac by following this. Under build-release/dist/bin the executable is js24 instead of js ( accoring to this ).
However, when I run the shell using js24, expressions like 1+2 is working, but when I try things like setTimeout(function () {}, 500) I am getting,
ReferenceError: setTimeout is not defined
What am I doing wrong ? I thought the behaviour would be same as the node shell.
Saving the excellent answers from the comments as an actual answer, so that this question can be marked as answered.
setTimeout is not part of the JavaScript language, it's part of the browser's window
object, which is the global object for a web page's JavaScript code: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout
node.js has a similar API: http://nodejs.org/docs/latest/api/timers.html#timers_settimeout_callback_delay_arg
To implement setTimeout in SpiderMonkey you can use this code: https://gist.github.com/kevinoid/3146420