修正された Function.prototype.toString

公開 · ECMAScript ES2019 をタグ付け

Function.prototype.toString() は、空白とコメントを含むソース コード テキストの正確なスライスを返すようになりました。以下は、古い動作と新しい動作を比較した例です。

// Note the comment between the `function` keyword
// and the function name, as well as the space following
// the function name.
function /* a comment */ foo () {}

// Previously, in V8:
foo.toString();
// → 'function foo() {}'
// ^ no comment
// ^ no space

// Now:
foo.toString();
// → 'function /* comment */ foo () {}'

機能サポート #