文章详情页
javascript - Leaking arguments
浏览:163日期: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. ddos - apache日志很多其它网址,什么情况?2. boot2docker无法启动3. css3 - css的伪类作用?4. 安卓某些机型播放HTML5 video会卡死5. 利用百度地图API定位及附件商家信息服务6. webpack - vue-cli写的项目(本地跑没有问题),准备放到Nginx服务器上,有什么配置需要改的?还有怎么部署?7. 微信公众号发送模板消息返回错误410008. javascript - 关于audio标签暂停的问题9. css - weui 用伪元素生成border,源码有点不理解10. javascript - 调微信分享朋友接口,出现下面问题,求解答,
排行榜
