我正在尝试使用文档中的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)
有人知道如何让这个工作吗?
答案 0 :(得分:4)
您无法分配到context
属性,您必须为其添加属性。你正在尝试用你自己的对象“覆盖”它。尝试自己分配每个属性:
var context = repl.start({}).context;
context.m = 'hello';
context.f = 'foo';