我有一个脚本foo.js,其中包含我想在REPL中使用的一些函数.
有没有办法让节点执行我的脚本,然后跳转到一个包含所有声明的全局变量的REPL,就像我可以使用python -i foo.py或ghci foo.hs?
在python中有一个很好的功能,python -i.例如,python -i myprogram.py将运行该程序,然后进入交互模式,就像我已将整个程序粘贴到交互式shell中一样.
node.js中是否有类似的命令?
在python中,我可以运行脚本并在该脚本的上下文中进入交互模式.这让我搞乱全局变量以及不检查程序状态的东西.
$ python -i hello.py
Run Code Online (Sandbox Code Playgroud)
我可以用Coffeescript做到这一点吗?我尝试过以下方法:
$ coffee -i hello.coffee
Run Code Online (Sandbox Code Playgroud)
不加载hello.coffee.它相当于咖啡-i
$ cat hello.coffee | coffee -i
Run Code Online (Sandbox Code Playgroud)
在REPL中逐行运行脚本,但在EOF之后结束REPL.
为什么我不能跑node -e ".load ./script.js"?
$ node -e '.load ./script.js'
[eval]:1
.load
^
SyntaxError: Unexpected token .
at Object.exports.runInThisContext (vm.js:53:16)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:410:26)
at node.js:578:27
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
Run Code Online (Sandbox Code Playgroud)
我尝试.用 a转义,\但这也不起作用。