2

I'm trying to play with the nodejs built in REPL from the documentation.

http://nodejs.org/api/repl.html

The example of adding an item is as follows:

repl.start().context.m = msg;

I cant seem to find away to add multiple menus. I've tried doing:

menus = {m = 'hello', f = 'foo'}
repl.start().context = menus

But that doesn't work either. I get:

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)

Does anybody know how to get this working?

1 Answer 1

4

You can't assign to the context property, you have to add properties to it. What you are trying is "overwriting" it with your own object. Try to assign each property by itself instead:

var context = repl.start({}).context;
context.m = 'hello';
context.f = 'foo';
Sign up to request clarification or add additional context in comments.

1 Comment

That worked. Im guessing javascript variables become pointers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.