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

prototype原型的一个问题
1)
Array.prototype.push   =   function(value){
this[this.length]   =   value;
alert( "aaaa ");
return   this.length;
}
var   testArray=new   Array();
var   lengthArray=testArray.push( "abc ");
alert(lengthArray);
2)
Array.prototype={
push:function(value){
this[this.length]   =   value;
alert( "bbbb ");
return   this.length;
}
}
var   testArray=new   Array();
var   lengthArray=testArray.push( "abc ");
alert(lengthArray);
------------------------------------------
为什么第一个能ALERT2个但第二个只能ALERT1个
请问2个写法有什么不同吗

------解决方案--------------------
第二个你没调到那个方法,使用了内置的函数
------解决方案--------------------
所有 JScript 内部对象都有只读的 prototype 属性。可以象该例中那样为原型添加功能,但该对象不能被赋予不同的原型。然而,用户定义的对象可以被赋给新的原型。
------解决方案--------------------
http://community.csdn.net/Expert/TopicView3.asp?id=5503463

差不多的问题~

参考