Wer kann helfen, das Konzept des „Leaking Arguments“ zu erklären?
<script> Benchmark.prototype.setup = function() { function otherFunc(a, b) { return a + b; } function withArguments(x) { var a = arguments; return otherFunc.apply(x, Array.prototype.slice.call(a, 1)); } function withCopy(x) { var a = []; var i, len = arguments.length; for (i = 1; i < len; i += 1) { a[i - 1] = arguments[i]; } return otherFunc.apply(x, a); }
传递
arguments
给任何方法被称为leaking arguments
withArguments
不会被V8优化,withCopy
那种 建议线上环境使用,虽然啰嗦。