I'm running this in node.js:
> x = { 'foo' : 'bar' }
{ foo: 'bar' }
> console.log(x)
{ foo: 'bar' }
undefined
> console.log("hmm: " + x)
hmm: [object Object]
undefined
What I don't understand is why console.log(x)
"pretty-prints" the object, whereas string concatenation "ugly-prints" it. And more importantly, what's the best way to make it print hmm: { foo: 'bar' }
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…