笔试遇到的题目,记录一下
把arguments转换为数组的方法
console.log(arguments instanceof Array);//false
var argsArray=Array.prototype.slice.call(arguments);
console.log(argsArray instanceof Array);//true
方法就是Array.prototype.slice.call(arguments);
同样也可以把getElementsByTagName的到的nodeList转换为数组
Array.prototype.slice.call(nodes);
本文介绍了一种将JavaScript中的arguments对象和getElementsByTagName方法获取的nodeList转换为数组的方法。通过使用Array.prototype.slice.call(),可以轻松实现这一转换。
1151

被折叠的 条评论
为什么被折叠?



