为什么 nodejs 在终端打印 ... 以进行解构赋值,以及如何在 *nix 的终端将 V8 安装到 运行 JavaScript?
Why does nodejs print ... at terminal for destructuring assignment and how to install V8 to run JavaScript at terminal at *nix?
阅读后 Running V8 Javascript Engine Standalone 决定尝试安装 V8
以达到 运行 宁 JavaScript 在 terminal
的明确目的。
的指导
$ sudo apt-get git
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
虽然还没有建成[V8][2]
。相反,首先尝试使用 nodejs
的链接问题中的建议。请注意,除了尝试使用 nodejs
来解决
之外,对 nodejs
的经验有限
$ sudo apt-get install nodejs
> x = 10*5
50
> x
50
> let {id} = {id:123}
...
... id
...
> id
ReferenceError: id is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
> {id} = {id:123}
ReferenceError: Invalid left-hand side in assignment
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:225:25)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
> x
50
> var y = 456
undefined
> y
456
> var [a, b] = [1,2]
... a
...
> function test(a = 123) {return a}
... test(5)
...
...
问题:
- 什么是
repl
?
- 为什么
nodejs
在 terminal
处无法识别 repl
处的解构赋值?
- 当运行宁
nodejs
时...
在terminal
是什么意思?
- 如何使用
nodejs
在终端上 运行 JavaScript 命令,包括解构赋值;默认参数;定义和调用函数;不会导致 ...
? 的其他常见用法
- 如何正确构建
V8
以便 运行 宁 JavaScript 在 terminal
?
(1) REPL = "Read-Eval-Print Loop",您在 shell 中为各种编程语言提供的那种交互式命令行。有关详细信息,请参阅 https://en.wikipedia.org/wiki/REPL。
(2) ...
表示节点shells认为您的输入还未完成。可能发生这种情况的一种特殊情况是,如果您的输入无法无误地解析(例如,如果您使用的是不受支持的语言功能)。这是 ...
有用的示例:
> function test(a) {
... return a;
... }
undefined
> test(5)
5
>
这也回答了您如何 define/call/run 一般情况下的问题。
(3) 在"parse error"情况下,可以用Ctrl+C跳出...
。
(4) 要构建 V8,请按照 https://github.com/v8/v8/wiki/Building-with-GN 中的说明进行操作。您将获得 d8
shell,它支持 V8 支持的所有 JavaScript 功能。但是请注意,它提供的系统集成(例如文件操作)比 node.js 少得多,因为 d8
用于 运行 测试和其他 V8 开发用例;它不会尝试用作通用 shell.
阅读后 Running V8 Javascript Engine Standalone 决定尝试安装 V8
以达到 运行 宁 JavaScript 在 terminal
的明确目的。
$ sudo apt-get git
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
虽然还没有建成[V8][2]
。相反,首先尝试使用 nodejs
的链接问题中的建议。请注意,除了尝试使用 nodejs
来解决
nodejs
的经验有限
$ sudo apt-get install nodejs
> x = 10*5
50
> x
50
> let {id} = {id:123}
...
... id
...
> id
ReferenceError: id is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
> {id} = {id:123}
ReferenceError: Invalid left-hand side in assignment
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:225:25)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
> x
50
> var y = 456
undefined
> y
456
> var [a, b] = [1,2]
... a
...
> function test(a = 123) {return a}
... test(5)
...
...
问题:
- 什么是
repl
? - 为什么
nodejs
在terminal
处无法识别repl
处的解构赋值? - 当运行宁
nodejs
时...
在terminal
是什么意思? - 如何使用
nodejs
在终端上 运行 JavaScript 命令,包括解构赋值;默认参数;定义和调用函数;不会导致...
? 的其他常见用法
- 如何正确构建
V8
以便 运行 宁 JavaScript 在terminal
?
(1) REPL = "Read-Eval-Print Loop",您在 shell 中为各种编程语言提供的那种交互式命令行。有关详细信息,请参阅 https://en.wikipedia.org/wiki/REPL。
(2) ...
表示节点shells认为您的输入还未完成。可能发生这种情况的一种特殊情况是,如果您的输入无法无误地解析(例如,如果您使用的是不受支持的语言功能)。这是 ...
有用的示例:
> function test(a) {
... return a;
... }
undefined
> test(5)
5
>
这也回答了您如何 define/call/run 一般情况下的问题。
(3) 在"parse error"情况下,可以用Ctrl+C跳出...
。
(4) 要构建 V8,请按照 https://github.com/v8/v8/wiki/Building-with-GN 中的说明进行操作。您将获得 d8
shell,它支持 V8 支持的所有 JavaScript 功能。但是请注意,它提供的系统集成(例如文件操作)比 node.js 少得多,因为 d8
用于 运行 测试和其他 V8 开发用例;它不会尝试用作通用 shell.