Function.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

概要

関数のソースコードを表す文字列を返します。

Function のメソッド
実装されたバージョン JavaScript 1.1
ECMAScript エディション ECMAScript 1st Edition

構文

function.toString(indentation)

引数

indentation 廃止 Gecko 17
ソースコードを表す文字列をインデントする空白文字の数です。indentation の値が -1 以下である場合は、ほとんどの不必要な空白文字が取り除かれます。

説明

Function オブジェクトは、Object から継承する toString メソッドをオーバーライドします。つまり、Object.prototype.toString を継承しません。Function オブジェクトについて、toString メソッドは関数宣言を表現するオブジェクトを表す文字列を返します。よって、toString は関数を逆コンパイルして function キーワード、引数の一覧、中かっこ、関数本体のソースコードを含む文字列を返します。

Function が文字列値として表現されるとき、JavaScript は自動的に toString メソッドを呼び出します。例えば、関数が文字列と連結されるときです。

関連情報

タグ (2)