已修改的 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 () {}'

功能支援 #