文章详情页
javascript - Leaking arguments
浏览:210日期:2023-03-31 15:59:32
问题描述
谁可以帮忙解释一哈 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); }
问题解答
回答1:传递arguments给任何方法被称为leaking arguments
不幸的是,传递arguments给任何参数,将导致Chrome和Node中使用的V8引擎跳过对其的优化,这也将使性能相当慢。
withArguments 不会被V8优化,withCopy 那种 建议线上环境使用,虽然啰嗦。
标签:
JavaScript
相关文章:
1. node.js - nodeJS 写入文件的内容怎么不是按次序的?2. 用CSS3 box-sizing 属性实现两个并排的容器,如果想让容器中间有间隔该如何实现3. javascript - 求一款靠谱点的移动端图片查看器插件,老司机速进!4. debian - docker依赖的aufs-tools源码哪里可以找到啊?5. docker gitlab 如何git clone?6. oop - Java中,关于匿名内部类调用外部类方法的疑惑7. javascript - angular左右滑动如何切换路由状态,????8. javascript - jquery hide()方法无效9. 这是什么情况???10. 网页爬虫 - Python爬虫入门知识
排行榜

网公网安备