function MyArray(){};//创建模拟数组功能的构造函数 MyArray.prototype.length=0;//解决IE下使用扩展子类 数组length的bug (function(){ var methods=['push','pop','shift','unshift','slice','splice','join']; for(var i=0;i<methods.length;i++){ (function(name){ MyArray.prototype[name]=function(){ return Array.prototype[name].apply(this,arguments); }; })(methods);//根据传进来的methods值 来继承Array } })(); var mine=new MyArray(); mine.push(1,2,3,4); console.log(mine.length); |