An error has occured: [object Object] error. ?
The cause of the error in my code(DEMO) a开发者_开发技巧nd how to fix?
An error has occured:
[object Object] error
DEMO
Change this:
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
Problem is that String
+ Object
results in the Object
being converted into a String
, the default result is what you see as [Object object]
.
Possible solutions:
- On custom objects define a
toString()
and return whatever you want to see in the output. - use
JSON.stringify(obj)
to convert it into something more useful, this will of course break in cases where circular references exist.
精彩评论