2012-09-17 2 views
2

설명서에서 REPL로 빌드 된 nodejs로 재생하려고합니다. 다음과 같이nodejs의 사용자 지정 REPL

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) 

누구나이 작업을 수행하는 방법을 알고 있습니까?

답변

4

context 속성에 할당 할 수 없으므로 속성을 추가해야합니다. 당신이 시도하는 것은 당신 자신의 물건으로 그것을 "덮어 쓰는 것"입니다. 대신 각 속성을 다음과 같이 할당하십시오.

var context = repl.start({}).context; 
context.m = 'hello'; 
context.f = 'foo'; 
+0

짐작되는 자바 스크립트 변수는 포인터가됩니까? – Menztrual