为什么流行音乐比移动快? [英] Why is pop faster than shift?
本文介绍了为什么流行音乐比移动快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
删除返回的项目而不重新 - 地址数组并使对它的所有引用无效, shift()
需要移动整个数组; pop()
可以简单地从长度中减去1。
Douglas Crockford, in JavaScript: The Good Parts, states that "shift is usually much slower than pop". jsPerf confirms this. Does anyone know why this is the case? From an unsophisticated point of view, they seem to be doing pretty much the same thing.
解决方案
To remove the returned item without re-addressing the array and invalidating all references to it, shift()
requires moving the entire array around; pop()
can simply subtract 1 from its length.
这篇关于为什么流行音乐比移动快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文