Can someone help me understand the following behavior? I would expect that since I can set global f from within this callback, I also have to change it. I don't understand very well how node handles context vs. global in REPL to understand this, and I would appreciate any insight.
Run REPL without useGlobal
$ cat test.js var repl = require('repl'); repl.start({useGlobal:false});
Now try setting f twice in a row:
$ node test.js > f ReferenceError: f is not defined > setTimeout(function(){f=1;}, 0); > f 1
It works for the first time ... now try again:
> setTimeout(function(){f=2;}, 0); > f 1
Ha!
The first launch installs it; the second does not affect her.
(Setting useGlobal : true I get the expected behavior.)
source share