.break和命令的.clear行为会有所不同,具体取决于您是从node命令启动 REPL 还是使用repl.start().
使用node命令时,.clear只是.break. 但是,如果您从 , 启动 REPL repl.start(),.clear则将按照您的预期清除本地上下文,并.break按照说明的方式运行。
这是.help从以下开始的 REPL 实例的样子node:
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
这就是以编程方式启动时的样子:
.break Sometimes you get stuck, this gets you out
.clear Break, and also clear the local context
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
.clear在 REPL 中使用也repl.start()将显示以下内容:
Clearing context...
下面是一个以编程方式使用 REPL 的示例:
var repl = require('repl');
var str = 'We can pass variables into a context.';
repl.start().context.str2 = str;
在此之后,我们打开了一个 CLI。如果我们键入str2,那么您将获得str. 如果清除上下文,那么str2上下文内部将不再存在。