如何在Node REPL中编写多行代码 [英] How to write multiple lines of code in Node REPL

查看:157
本文介绍了如何在Node REPL中编写多行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想评估

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

而不是逐行评估

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

是否有一种简单的方法将提示移至

Is there a simple way to move the prompt to the next line?

推荐答案

节点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

这篇关于如何在Node REPL中编写多行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆