以类数组对象的形式存储函数实参。
1、作用:
-
获取实参。
-
arguments.callee()方法返回当前方法,可以用于递归。
let organizeArr = [
{
id: '01',
name: 'xiaoming',
children: [
{
id: '0101',
name: 'xiaoming1',
children: [
{
id: '010101',
name: 'xiaoming2',
children: []
}
]
},
{
id: '0102',
name: 'xiaoming3',
children: [
{
id: '010201',
name: 'xiaoming4',
children: []
}
]
}
]
}
]
function printName(arr) {
console.log(arguements);
arr.forEach(item => {
console.log(item.name);
if(item.children && Array.isArray(item.children)) {
// 这里递归
arguments.callee(item.children)
}
});
}
printName(organizeArr);
2、转变成数组方法:toArray()
/**
* 取自vue2.0源码 将一个类数组对象转化成数组
* Convert an Array-like object to a real Array.
*/
function toArray (list, start) {
start = start || 0;
var i = list.length - start;
var ret = new Array(i);
while (i--) {
ret[i] = list[i + start];
}
return ret
}