⭐️ 特点

function test() {
	console.log(arguments);
}
test(1, 2, 3, 4);

Untitled

构建类数组

var obj = {
	0: 0,
  1: 1,
  2: 2,
  length: 3
};
console.log(obj);

Untitled

⭐️ 为自建类数组添加继承自 Array 的 splice 方法,使其成为 [] 而不是 {}

var obj = {
	0: 0,
  1: 1,
  2: 2,
  length: 3,
  splice: Array.prototype.splice
};
console.log(obj);

Untitled

⭐️ 实现 push 方法

var obj = {
	'2': 3,
  '3': 4,
  length: 2,
  'splice': Array.prototype.splice,
  'push': Array.prototype.push
}
obj.push(1);
obj.push(2);
console.log(obj);

Untitled

// 原理
Array.prototype.push = function(el) {
	this[this.length] = el;
  this.length++;
}

var obj = {
	'2': 3,
  '3': 4,
  length: 2,
  'splice': Array.prototype.splice,
  'push': Array.prototype.push
}

obj.push(1);
// obj[2] = 1
obj.push(2);
// obj[3] = 2
console.log(obj);

Untitled

⭐️ typeof / arguments

function test() {
  console.log(typeof(arguments));
}

test();

// 返回 object