javascript - Leaking arguments
問題描述
誰可以幫忙解釋一哈 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給任何參數(shù),將導(dǎo)致Chrome和Node中使用的V8引擎跳過對其的優(yōu)化,這也將使性能相當(dāng)慢。
withArguments 不會被V8優(yōu)化,withCopy 那種 建議線上環(huán)境使用,雖然啰嗦。
相關(guān)文章:
1. 怎么在phpstudy中用phpexcel上傳數(shù)據(jù)到MYSQL?2. javascript - 百度搜索網(wǎng)站,如何讓搜索結(jié)果顯示一張圖片加上一段描述,如圖;求教3. phpadmin的數(shù)據(jù)庫,可以設(shè)置自動變化時間的變量嗎?就是不需要接收時間數(shù)據(jù),自動變化4. html5和Flash對抗是什么情況?5. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?6. html - 爬蟲時出現(xiàn)“DNS lookup failed”,打開網(wǎng)頁卻沒問題,這是什么情況?7. mac里的docker如何命令行開啟呢?8. boot2docker無法啟動9. 這是什么情況???10. gosts內(nèi)容是空的
