日期:2014-05-16  浏览次数:20354 次

正在学继承,请问怎样让我自己的自定义对象继承Array对象?
这样不行,请问该怎样写?
<script type="text/javascript">
function shuzu(a,b,c){
  Array.call(this,a,b,c)
}
shuzu.prototype=new Array();
arr1=new shuzu(1,2,3)
alert(arr1)
</script>

------解决方案--------------------
JScript code

var myArray=function(){
   var x=Array.apply(null,arguments);
   for(var p in x)this[p]=x[p];
   this.length=x.length;
};
myArray.prototype=new Array();
myArray.prototype.constructor=myArray;

------解决方案--------------------
探讨

引用:
JScript code

var myArray=function(){
var x=Array.apply(null,arguments);
for(var p in x)this[p]=x[p];
this.length=x.length;
};
myArray.prototype=new Array();
myArray.prototype.c……