我想在Nodes.js REPL模式下执行多行,如下所示。但我遇到了以下错误。如何解决这个问题呢?非常感谢。
{
... var foo = [];
... }
SyntaxError:意外的标识符
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:137:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393: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)
答案 0 :(得分:0)
如果要执行多行,只需定义Immediately-Invoked Function Expression,如下所示:
(function () {
var foo = [];
})();