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 () {}'
功能支援 #
- Chrome: 自版本 66 起支援
- Firefox: 已支援
- Safari: 不支援
- Node.js: 自版本 8 起支援
- Babel: 不支援