Why ...args isn't transpiled to Array.prototype.slice.call(arguments)? #12667
-
When I write: function foo(...args) {
// …
} it gets transpiled to function foo() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// …
} the same could be achieved by function foo() {
var args = Array.prototype.slice.call(arguments);
// …
} so my question is - why? Is it some spec quirk? Is it safer? What's the benefit of using for loop here? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
See https://stackoverflow.com/a/2143894/1490357 technically |
Beta Was this translation helpful? Give feedback.
-
IIRC one reason is that passing |
Beta Was this translation helpful? Give feedback.
IIRC one reason is that passing
arguments
to another function causes a perf drop in some V8 versions.