toString() (Function/global)

Returns a string representation of the receiving object.


JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Property/method value type:String primitive
JavaScript syntax:-myObject.toString()
Argument list:aRadixRadix conversion can be applied when the receiver is a number

The generic behavior of this method is to return a String primitive representation of the receiving object. It is generally overridden on a class by class basis due to objects containing such different properties and values.

The ToString internal operator is called. This doesn't usually tell you very much. The default toString() handlers may be different for the built-in classes, but all you'll likely get from a class you create yourself will be the string "[object Object]".

You will need to override the toString() function that is provided by default and add your own. This should be added to the prototype of your class.

The generic version of the toString() method may be useful when debugging. You can use the apply() method to force its use on objects you are trying to inspect and which may have overridden the toString() method themselves.

This method is supported by virtually every object by virtue of the fact that it is available as a method of the Global object in Netscape. Therefore it gets inherited into the scope chain for every script and function (method).


See also:Array.toString(), Boolean.toString(), Conversion, Date.toString(), Error.toString(), Function.toString(), Number.toString(), Object.toString(), prototype.toString(), RegExp.toString(), String, String concatenate (+), String.toString(), ToString