TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JavaScript – Array Direct Assignment

14 点作者 suhair将近 12 年前

3 条评论

marijn将近 12 年前
See also this benchmark, which seems to have very different results from the scottlogic link: <a href="http://jsperf.com/array-push-vs-array-length23333/2" rel="nofollow">http://jsperf.com/array-push-vs-array-length23333/2</a><p>I just re-ran it on FF24 (nightly), and also saw results where .push beats this kludge.<p>So before everyone runs off and takes 'direct array assignment is fast' as a rule of thumb, please consider that it quite probably isn't.
评论 #5809606 未加载
rjett0将近 12 年前
I prefer readable code to hacks. Unless you absolutely have a hot spot in your code that will benefit, readability should outweigh this. JavaScript engines will catch up.
jfaucett将近 12 年前
after reading the underscore source I remember wondering if direct array assignment was really significantly better than calling push. here's a quick link to the perf reference made in the article: <a href="http://www.scottlogic.co.uk/2010/10/javascript-array-performance/" rel="nofollow">http://www.scottlogic.co.uk/2010/10/javascript-array-perform...</a>, oddly interesting is that calling push was faster in chrome than in direct assignment. I wonder what the results would be like in newer browsers...
评论 #5809137 未加载