Say in JavaScript I create a simple object:
function MyObj() {
this.prop = "property";
}
Now if I create an instance of this and the output it to console I see the object representation:
var obj = new MyObj();
console.log(obj);
How can I instead make that output a string?: For example, I would like that the console displays My property value is 'property'
rather than [object object].
I've tried using MyObj.prototype.toString
, but it doesn't seem to work.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…