Javascript 创建扩展本机数组的集合有什么危险?

Javascript 创建扩展本机数组的集合有什么危险?,javascript,arrays,oop,Javascript,Arrays,Oop,我基于此创建了一个集合。我发现它在chrome、firefox和ie9+上运行。 我想有些事情是行不通的,或者说ie9的Windows10模拟器没有给我真实的画面 这个扩展会出什么问题 测试代码: <script> function Collection() { var collection = Object.create( Array.prototype ); collection = (Array.apply( collection, a

我基于此创建了一个集合。我发现它在chrome、firefox和ie9+上运行。 我想有些事情是行不通的,或者说ie9的Windows10模拟器没有给我真实的画面

这个扩展会出什么问题

测试代码:

<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>

函数集合(){
var collection=Object.create(Array.prototype);
collection=(Array.apply(collection,arguments)| collection);
回收;
}
Collection.prototype=Object.create(Array.prototype);
var collection=新集合();
集合[0]=1;
console.log(集合[0]);
看一看

特别是,

创建从
数组.prototype
而不是
集合.prototype
继承的对象。它创建的是一个对象,而不是数组

数组
忽略其
值。并创建一个
数组
实例,而不是
集合
实例

这是毫无意义的,因为
Array
从不返回错误值,所以
collection
总是被忽略

这个扩展会出什么问题


它创建
数组
s,而不是
集合
s。根本没有扩展。尝试将一些方法放在
Collection.prototype
并调用它们。

另一个要点:
Collection.push('hello');collection.length=0;集合[0];/'您好“
@kaido,就是说它是一个对象而不是一个数组,是的。
var collection = Object.create(Array.prototype);
collection = (Array.apply( collection, arguments ) …
… || collection)