Function.prototype.toString()
now returns exact slices of source code text, including whitespace and comments. Here’s an example comparing the old and the new behavior:
// 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 () {}'
Feature support #
- Chrome: supported since version 66
- Firefox: supported
- Safari: no support
- Node.js: supported since version 8
- Babel: no support