ActionScript for Flash MX: The Definitive Guide, Second Edition

ActionScript for Flash MX: The Definitive Guide, 2nd EditionBy Colin Moock
Chapter 18.  ActionScript Language Reference
Function.toString( ) Method Flash 5

returns a string representation of the function object

theFunction.toString()

Returns

A string representing the function object.

Description

The toString( ) method returns a string describing theFunction. By default, all functions return the string "[type Function]". Checking the return value of toString( ) can be useful during debugging, as it distinguishes function objects from other objects. The instanceof and typeof operators can also be used to determine the datatype of a Function object. For example:

function moveClipTo (newX, newY) { this._x = newX; this._y = newY; } trace(moveClipTo.toString()); // Displays: [type Function] trace(typeof moveClipTo); // Displays: function trace(moveClipTo instanceof Function); // Displays: true

To provide a more descriptive return value for toString( ), you can override the toString( ) method for the function:

moveClipTo.toString = function () { return "moveClipTo function"; }; trace(moveClipTo.toString()); // Displays: moveClipTo function

See Also

instanceof, Object.toString( ), typeof

    Категории