asfman
有些事,我们明知道是错的,也要去坚持,因为不甘心;有些人,我们明知道是爱的,也要去放弃,因为没结局;有时候,我们明知道没路了,却还在前行,因为习惯了。
posts - 88,  comments - 180,  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 汪杰 阅读(281) 评论(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;
}  回复  更多评论
  

每天10分钟,轻松学英语
专题:iPad  jQuery  Chrome OS
博客园首页  IT新闻  程序员微博  招聘频道  学英语
标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)
 
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
Windows 7专题

相关链接:

<2010年3月>
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(14)

随笔分类

随笔档案(88)

文章分类(660)

文章档案(637)

收藏夹

http://blog.csdn.net/prodigynonsense

最新随笔

搜索

  •  

积分与排名

  • 积分 - 147725
  • 排名 - 9

最新随笔

最新评论

阅读排行榜

评论排行榜