javascript - Leaking arguments
怪我咯
怪我咯 2017-07-05 10:42:40
0
1
853

Who can help explain the concept of Leaking arguments

<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);
  }
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
某草草

Passing arguments to any method is called leaking arguments

Unfortunately, passing arguments to any parameter will cause the V8 engine used in Chrome and Node to skip optimizing it, which will also make performance quite slow.

withArguments will not be optimized by V8, withCopy is recommended for use in online environments, although it is verbose.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!