3

In the Node.js REPL, if you type String.prototype, an empty object: {} is returned. But if you type it in the Chrome JavaScript console, an object is returned with the expected function names and functions.

Why doesn't Node.js exhibit this behavior? How can I access the native String functions in Node.js?

2 Answers 2

4

According to the IRC users on FreeNode/#node.js

BennyLava: Object.getOwnPropertyNames(String.prototype)

jmar777: because in the REPL you basically get the result of calling toString() on the result, whereas the chrome console has some fancy interactive display of objects

BennyLava: they're just not enumerable

So the answer is Object.getOwnPropertyNames(String.prototype).

Sign up to request clarification or add additional context in comments.

3 Comments

Really? Logging an object works fine - you don't get [object Object] as a string.
@pimvdb Oh, regarding the jmar777 comment? Ya, I think it has to do with the fact that they're not enumerable, and that's why they don't show up.
@pimvdb: That's because console.log doesn't just print the argument's toString.
0

You could use node-inspector to get the Inspector experience for Node.

node-inspector

Comments

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.