asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
<script>
var b=[];
Array.prototype.push=function()
{
 var l=arguments.length;
 for(var i=0;i<l;i++)
 {
   this[this.length]=arguments[i];
 }
}
Array.prototype.pop = function() {
            if (this.length === 0) {return undefined;}
            var temp=this[this.length-1];
            --this.length;
            return temp;
        }
var a=[1,2,3];
a.push.apply(b,[4,5,6]);
alert(a);
alert(b);
a.push.apply(a,[4,5,6]);
alert(a);
</script>
因为当上下文为b的时候执行push的过程就如:
b[0]=4;
b[1]=5;
b[2]=6;
所以对a没有任何影响
posted on 2007-04-25 15:03 汪杰 阅读(702) 评论(3)  编辑 收藏 引用

FeedBack:
# re: think about push and pop
# re: think about push and pop
2008-04-27 15:57 | 汪杰
Array.prototype.push=function()
{
var l=arguments.length;
for(var i=0;i<l;i++)
{
this[this.length++]=arguments[i];
}
}  回复  更多评论
  
# re: think about push and pop
2008-04-27 15:57 | 汪杰
function setArray(obj, elems)
{
obj.length = 0;
Array.prototype.push.apply(obj, elems);
return obj;
}  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 456688
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜