1
我创建了一个基于这个article的集合。我发现它运行在chrome,firefox和ie9 +上。 我认为有些事情不会起作用,或者,ie10模拟器对于Windows 10并不能给我真实的图像。创建扩展本地数组的集合有什么危险?
这个扩展会出现什么问题?
测试代码:
<script>
function Collection() {
var collection = Object.create(Array.prototype);
collection = (Array.apply(collection, arguments) || collection);
return collection;
}
Collection.prototype = Object.create(Array.prototype);
var collection = new Collection();
collection[0] = 1;
console.log(collection[0]);
</script>
另一个重点:'collection.push('hello'); collection.length = 0;集合[0]; //'你好'。 – Kaiido
@Kaiido当它是一个对象而不是数组时,是的。 – Bergi