且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Node REPL中编写多行代码

更新时间:2023-11-24 18:54:16

节点v6.4具有编辑器模式。在repl提示符下,键入 .editor ,然后您可以输入多行。

Node v6.4 has an editor mode. At the repl prompt type .editor and you can input multiple lines.

example

$ 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

Here are the docs on all the special repl commands https://nodejs.org/api/repl.html#repl_commands_and_special_keys