node.js - 如何在 Node REPL 中编写多行代码

标签 node.js command-prompt read-eval-print-loop node-repl

我想评价

var foo = "foo";
console.log(foo);

作为一个 block ,而不是逐行评估

var foo = "foo";
undefined
console.log(foo);
foo
undefined

有没有一种简单的方法可以将提示移到下一行?

最佳答案

Node v6.4 具有 editor 模式。在 repl 提示符下输入 .editor 可以输入多行。

例子

$ node                                                                                                   
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
const fn = there => `why hello ${there}`;
fn('multiline');
// hit ^D 
'why hello multiline'
> // 'block' gets evaluated and back in single line mode.

这里是所有特殊 repl 命令的文档 https://nodejs.org/api/repl.html#repl_commands_and_special_keys

关于node.js - 如何在 Node REPL 中编写多行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29203892/

相关文章:

javascript - 在浏览器中接收 WebSocket ArrayBuffer 数据 - 而不是接收字符串

javascript - Node.js https.request : Access the requested data from the callback response scope

c++ - 控制台关闭时从 GUI 应用程序附加控制台

python - 在 Python 2.7 中使用语句 True 和 False

swift - 导入框架构建以在 Swift REPL 中进行测试失败?

python - 为什么我在 Python 控制台中得到 None 元组的打印,而不是单个 None 的打印?

scala - 使用 scala 执行 SparkStreaming 程序时连接被拒绝

javascript - 尝试使用 jade 渲染 html 文件,但它仍然将其定位为 jade

找不到目录文件夹内的文件夹中的 python 文本文件

node.js - 中止等待请求 promise