我正在尝试使用文档中 REPL 中内置的 Nodejs。
http://nodejs.org/api/repl.html
添加项目的示例如下:
repl.start().context.m = msg;
我似乎无法找到添加多个菜单的方法。我尝试过这样做:
menus = {m = 'hello', f = 'foo'}
repl.start().context = menus
但这也行不通。我得到:
testREPL> m
TypeError: needs a 'context' argument.
at REPLServer.self.eval (repl.js:113:21)
at Interface.<anonymous> (repl.js:250:12)
at Interface.EventEmitter.emit (events.js:88:17)
at Interface._onLine (readline.js:199:10)
at Interface._normalWrite._line_buffer (readline.js:308:12)
at Array.forEach (native)
at Interface._normalWrite (readline.js:307:11)
at Socket.ondata (readline.js:90:10)
at Socket.EventEmitter.emit (events.js:115:20)
at TCP.onread (net.js:395:14)
有人知道如何让它工作吗?
最佳答案
您无法分配给 context
属性,您必须向其添加属性。您正在尝试的是用您自己的对象“覆盖”它。尝试单独分配每个属性:
var context = repl.start({}).context;
context.m = 'hello';
context.f = 'foo';
关于node.js - Nodejs 中的自定义 REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12455708/