Saturday, December 11, 2010

dumping globals in node.js REPL

This seems handy in the node REPL.  It exploits a JS3 flaw in the failure to send new to a function 'creating' an instance.  The this in the dump function gets the context above and not ourself.
> function Fexp() { for (var v in this) { console.log(v) }; return this}
> var ex = Fexp();
global
process
GLOBAL
root
setTimeout
setInterval
clearTimeout
clearInterval
console
Buffer
module
require
_
from my running console. Was there an easier way?
See http://nodejs.org/docs/v0.3.1/api/repl.html

No comments: