ES6语法 Array.from(arr)
let list = Array.from(hdList);
用Array.prototype.slice.call(elems)
方法转化为数组 或 [].slice.call(elems)
let list = Array.prototype.slice.call(hdList);
list.forEach((current,index) => {
current.addEventListener('click',() => {
animationFn(index);
},false);
});
用[ ...elems ]
方法转化为数组
let list = [...hdList];
用Array.prototype.forEach.call(elem,callback)
方法
Array.prototype.forEach.call(hdList,function(){
})
Array.prototype.map.call(hdList,function(){
})
用Array.prototype.forEach.apply(elem,[callback])
方法
Array.prototype.forEach.apply(hdList,[(current,index) => {
current.addEventListener('click',() => {
animationFn(index);
},false);
}]);
用bind方法
Array.prototype.forEach.bind(hdList)((current,index) => {
current.addEventListener('click',() => {
animationFn(index);
},false);
});