我在研究 jQuery 源码时发现了这个(v1.5 第 2295 行):
I was studying the jQuery source when I found this (v1.5 line 2295):
namespace = new RegExp("(^|\.)" +
jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\.(?:.*\.)?") + "(\.|$)");
我的问题是,为什么在这里使用 slice(0)?
My question is, why use slice(0) here?
sort() 修改了它被调用的数组 - 绕过其他代码可能会改变的东西并不是很好依靠.
sort() modifies the array it's called on - and it isn't very nice to go around mutating stuff that other code might rely on.
slice() 总是返回一个新数组 - slice(0) 返回的数组与输入相同,这基本上意味着它是复制一个廉价的方法数组.
slice() always returns a new array - the array returned by slice(0) is identical to the input, which basically means it's a cheap way to duplicate an array.
这篇关于.slice(0) 在这里有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
检查一个多边形点是否在传单中的另一个内部Check if a polygon point is inside another in leaflet(检查一个多边形点是否在传单中的另一个内部)
更改传单标记群集图标颜色,继承其余默认 CSSChanging leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改传单标记群集图标颜色,继承其余默认
触发点击传单标记Trigger click on leaflet marker(触发点击传单标记)
如何更改 LeafletJS 中的默认加载磁贴颜色?How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默认加载磁贴颜色?)
将 Leaflet 图层控件添加到侧边栏Adding Leaflet layer control to sidebar(将 Leaflet 图层控件添加到侧边栏)
Leaflet - 在弹出窗口中获取标记的纬度和经度Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在弹出窗口中获取标记的纬度和经度)