Bootstrap 5 Javascript examples sometimes show code like:
var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
Why isn't this just:
var collapseElementList = document.querySelectorAll('.collapse')
What is [].slice.call()
doing exactly? I don't understand why you'd slice
on an empty array, and then I have no idea what call
is doing there. What would be the problem with the obvious way to do this, the second way above?