Function.prototype.toSource()

  • Revision slug: JavaScript/Reference/Global_Objects/Function/toSource
  • Revision title: Function.toSource
  • Revision id: 310731
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{ Non-standard_header() }}

Summary

Returns a string representing the source code for the function.

Method of Function
Implemented in JavaScript 1.3
ECMAScript Edition none

Syntax

var sourceString = function.toSource();

Parameters

None.

Description

The toSource method returns the following values:

  • 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

Revision Source

<div>
  {{ Non-standard_header() }}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Returns a string representing the source code for the function.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Method of <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function"><code>Function</code></a></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.3</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>none</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
var sourceString = <em>function</em>.toSource();</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h2 id="Description" name="Description">Description</h2>
<p>The <code>toSource</code> method returns the following values:</p>
<!-- 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. -->
<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>
<code>function Function() {
    [native code]
}</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>
<h2 id="See_Also" name="See_Also">See Also</h2>
<ul>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function/toString" title="JavaScript/Reference/Global_Objects/Function/toString">toString</a></li>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/valueOf" title="JavaScript/Reference/Global_Objects/Object/valueOf">Object.prototype.valueOf</a></li>
</ul>
<!-- OLD DATA --><!-- languages({
"fr": "fr/docs/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Function/toSource"
}) -->
Revert to this revision