Simple JavaScript REPL for the browser.
By default it evals JS:
repl() // JavaScript eval mode
but you can pass it a callback instead:
repl(function(s) { return eval(s); });
The second argument is the default message first displayed:
repl(null, "eval some JS!");
-10
could simply be replaced by~9
,while
could be replaced byfor
.Also, it seems there is no need to coerce the
r
, asprompt
does it for you.function(c,t,h,r){for(h=[t||""];s=prompt(h.slice(~9).join("\n"));h.push(r))try{r=(c||eval)(s)}catch(e){r=e};}