I stumbled onto this neat shortcut for converting a DOM NodeList into a regular array, but I must admit, I don't completely understand how it works:(我偶然发现了将DOM NodeList转换为常规数组的简洁快捷方式,但我必须承认,我并不完全理解它是如何工作的:)
[].slice.call(document.querySelectorAll('a'), 0)
So it starts with an empty array []
, then slice
is used to convert the result of call
to a new array yeah?(所以它以空数组[]
开头,然后使用slice
将call
结果转换为新数组是啊?)
The bit I don't understand is the call
.(我不明白的是call
。) How does that convert document.querySelectorAll('a')
from a NodeList to a regular array?(如何将document.querySelectorAll('a')
从NodeList转换为常规数组?)
ask by Yansky translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…