I have a javascript function which takes a parameter, like:
function getSomething(cat,handler) {
varURI = 'text'+cat;
document.write('<p>'+varURI+'</p>');
}
What I see in the output is:
text[object Object]
How do I get the real textual value of the Object?
You need to override the
toStringmethod of the object -and give your object a “textual value”-.You are getting
"[object Object]"because the inheritedObject.prototype.toStringmethod is being executed, for example:This own
toStringmethod will be executed when you make any implicit to string conversion (like when you concatenate a string to it), e.g.:Note: If you mean by “textual value” a “string representation” of the object, (e.g. listing property/value pairs), your function will need to enumerate all the properties (using the
for-instatement), but usually most of the time, that’s done for debugging purposes, if that’s the case, I would recommend you to get a debugger (like Firebug), and use theconsole.dirmethod.