Function.prototype.toSource()

  • Revision slug: JavaScript/Reference/Global_Objects/Function/toSource
  • Revision title: toSource
  • Revision id: 88240
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment Reverted to earlier version; 4 words added, 4 words removed

Revision Content

{{ Non-standard_header() }}

Summary

Returns a string representing the source code for the function.

Method of Function
Implemented in: JavaScript 1.3

Syntax

var sourceString = function.toSource();

Parameters

None.

Description

The toSource method returns the following values:

This shouldn't be here, but until reorganization where pages are moved to their proper places, the title of this article is ambiguous, so it can stay. After reorganization, this should be removed.

  • For the built-in Function object, toSource returns the following string indicating that the source code is not available:
function Function() {
   [native code]
}
  • For custom functions, toSource returns the JavaScript source that defines the object as a string.

This method is usually called internally by JavaScript and not explicitly in code. You can call toSource while debugging to examine the contents of an object.

See Also

{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Function/toSource", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Function/toSource" } ) }}

Revision Source

<p>
{{ Non-standard_header() }}
</p>
<h3 name="Summary"> Summary </h3>
<p>Returns a string representing the source code for the function.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.3</td>
</tr>
</tbody></table>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval">var sourceString = <em>function</em>.toSource();
</pre>
<h3 name="Parameters"> Parameters </h3>
<p>None.
</p>
<h3 name="Description"> Description </h3>
<p>The <code>toSource</code> method returns the following values:
</p><p><span class="comment">This shouldn't be here, but until reorganization where pages are moved to their proper places, the title of this article is ambiguous, so it can stay. After reorganization, this should be removed.</span>
</p>
<ul><li> For the built-in <code>Function</code> object, <code>toSource</code> returns the following string indicating that the source code is not available:
</li></ul>
<pre class="eval">function Function() {
   [native code]
}
</pre>
<ul><li> For custom functions, <code>toSource</code> returns the JavaScript source that defines the object as a string.
</li></ul>
<p>This method is usually called internally by JavaScript and not explicitly in code. You can call <code>toSource</code> while debugging to examine the contents of an object.
</p>
<h3 name="See_Also"> See Also </h3>
<ul><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Function/toString">toString</a>
</li><li><a href="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/valueOf">Object.prototype.valueOf</a>
</li></ul>

{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Function/toSource", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Function/toSource" } ) }}
Revert to this revision