我正在通过Linux终端使用nodejs REPL.我有很大一部分代码要粘贴到nodejs中.但是,粘贴代码会导致终端在一段时间内无响应.这是因为REPL使用表达式的每一行吐出以下文本:
Array Boolean Date Error EvalError
Function Infinity JSON Math NaN
Number Object RangeError ReferenceError RegExp
String SyntaxError TypeError URIError decodeURI
decodeURIComponent encodeURI encodeURIComponent eval isFinite
isNaN parseFloat parseInt undefined
ArrayBuffer Buffer DataView FMM Float32Array
Float64Array GLOBAL Int16Array Int32Array Int8Array
Uint16Array Uint32Array Uint8Array Uint8ClampedArray _
assert buffer child_process clearImmediate clearInterval
clearTimeout cluster console crypto dgram
dns domain escape events fs
global http https module net
os path process punycode querystring
readline require root setImmediate setInterval
setTimeout stream string_decoder tls tty
unescape url util vm zlib
__defineGetter__ __defineSetter__ __lookupGetter__ __lookupSetter__ constructor
hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString
valueOf
Run Code Online (Sandbox Code Playgroud)
这有点烦人.我知道我可以通过将其粘贴到文件并将其加载到REPL中来解决它:
.load some-file.js
Run Code Online (Sandbox Code Playgroud)
但是我想知道是否有办法通过单独粘贴来做到这一点,而且我确信必须有时间和地点.
问题是您的代码使用制表符进行缩进,而Node.js REPL将制表符视为自动完成的提示.
要解决此问题,请使用.editor忽略制表符的命令:
$ node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function a() {
console.log('hello world');
}
a();
// type ^D here
hello world
undefined
>
Run Code Online (Sandbox Code Playgroud)
.editor是Node.js v6.4.0中添加的一项功能,所以如果你碰巧使用的是旧版本,那你就不走运了.
有关这些特殊REPL命令的更多信息,请查看Node.js文档.
| 归档时间: |
|
| 查看次数: |
1926 次 |
| 最近记录: |