3.2.0

why document.write(obj);? (a basic js question)

hello!

at first: beautiful script!


and here my basic questions:

i don't know why "document.write(obj);" write a output.
it works fine but why??? ;)

if i write "document.write(obj.toString);" i become the function-code as output. but why - the return value is a string and our comment:
Direct or implicit
call to ‘toString’ method returns properly formatted HTML
markup string, which can be used in document.write() call or
assigned to the page innerHTML property.

direct -> source of this function
implicit -> why javascript know to implicit called this method?


i hope yout understand my problem...

thank you for your answer!

bye franky
(and sorry for my english)

franky
June 24,
You should use
document.write(obj.toString());

otherwise instead of executing the function you just provide reference to the function object. The function object has its own .toString method which returns function text.

Javascript invokes toString() method automatically when it expects text value, for example in string concatenation, string comparison, document.write(...), array[...]
Alex (ActiveWidgets)
June 24,

This topic is archived.

See also:


Back to support forum