shm*_*uli 2 javascript node.js read-eval-print-loop
是.clear元命令完全相同一样.break元命令,或者是它的一个变化?我知道他们都可以用来突破一个...提示(表明你还没有完成你的命令)而不退出REPL,就像打击一样CTRL+C.但是.clear和之间有什么根本区别.break吗?
我已经在很多地方读过,在node.js REPL中,.clear元命令是为了消除你在内存中可能没有重启REPL的任何变量或闭包.
预期的行为是否可以声明变量,运行.clear命令,再次调用该变量,发现它是空的/非声明的?在我使用.clear命令时,我还没有找到工作.
该.break和.clear命令运作方式,取决于你是否开始从该REPL node命令,或使用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
Run Code Online (Sandbox Code Playgroud)
这是以编程方式启动时的样子:
.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
Run Code Online (Sandbox Code Playgroud)
.clear在开始使用的REPL中repl.start()也会显示:
Clearing context...
Run Code Online (Sandbox Code Playgroud)
以下是以编程方式使用REPL的示例:
var repl = require('repl');
var str = 'We can pass variables into a context.';
repl.start().context.str2 = str;
Run Code Online (Sandbox Code Playgroud)
在此之后,我们打开了一个CLI.如果我们输入,str2那么你将得到的内容str.如果清除上下文,则上下文str2中将不再存在.
| 归档时间: |
|
| 查看次数: |
1760 次 |
| 最近记录: |