阅读运行v8 javaScript引擎后,决定尝试安装V8
,以明确目的是在terminal
上运行JavaScript。
按照安装depot_tools的指导
$ 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
以解决如何测试JQUERY 3.0 Beta的承诺/a 兼容吗?
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
,以便在terminal
上运行JavaScript?
(1(replain =" read-eval-print loop",这是您在各种编程语言中使用的交互式命令行。有关更多详细信息,请参见https://en.wikipedia.org/wiki/repl。
(2(...
表示节点外壳认为您的输入尚未完成。可能发生这种情况的一种特殊情况是,如果您的输入无法在没有错误的情况下解析(例如,如果您使用的是不支持的语言功能(。这是...
有用的示例:
> function test(a) {
... return a;
... }
undefined
> test(5)
5
>
这也回答了您的问题如何定义/呼叫/运行的东西。
(3(在"解析错误"案例中,您可以使用ctrl c。
脱离...
(4(要构建V8,请遵循https://github.com/v8/v8/wiki/building-with-gn-with-gn的说明。您将获得d8
Shell,它支持V8支持的所有JavaScript功能。但是请注意,它提供的系统集成(例如文件操作(比Node.js少得多,因为d8
用于运行测试和其他V8开发用例;它并不能用作通用外壳。