文章詳情頁
javascript - Leaking arguments
瀏覽:249日期: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. html5 - datatables 加載不出來數據。2. node.js - mongodb查找子對象的名稱為某個值的對象的方法3. 測試自動化html元素選擇器元素ID或DataAttribute [關閉]4. html5和Flash對抗是什么情況?5. javascript - QQ第三方登錄的問題6. 運行python程序時出現“應用程序發生異?!钡膬却驽e誤?7. 利用IPMI遠程安裝centos報錯!8. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統有創建日志文件,不寫入日志信息。9. spring-mvc - spring-session-redis HttpSessionListener失效10. 正在使用electron和node.js做桌面應用,需要實時監聽是否有網絡連接,node或者electron是否可以做到
排行榜

網公網安備