Function.prototype.toString

Did you know that you can read content offline by using one of these tools? If you would like to read offline MDN content in another format, let us know by commenting on Bug 665750.

Dash App

Summary

Returns a string representing the source code of the function.

Method of Function
Implemented in JavaScript 1.1
ECMAScript Edition ECMAScript 1st Edition

Syntax

function.toString(indentation)

Parameters

indentation Obsolete since Gecko 17
The amount of spaces to indent the string representation of the source code. If indentation is less than or equal to -1, most unnecessary spaces are removed.

Description

The Function object overrides the toString method inherited from Object; it does not inherit Object.prototype.toString. For Function objects, the toString method returns a string representation of the object in the form of a function declaration. That is, toString decompiles the function, and the string returned includes the function keyword, the argument list, curly braces, and the source of the function body.

JavaScript calls the toString method automatically when a Function is to be represented as a text value, e.g. when a function is concatenated with a string.

Notes

Since Firefox 17, Function.prototype.toString() has been implemented by saving function's source, the decompiler was removed.so we dont't need indentation parameter any more. See bug https://bugzilla.mozilla.org/show_bug.cgi?id=761723

See also

Tags (2)