asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
<script>
Array.prototype.slice=function(n){
var temp=[];
for(var i=0;i<this.length;i++)
{
if(i>=n||i<0)
temp.push(this[i]);
}
return temp;
}
function a(){
return Array.prototype.slice.call(arguments,2);
}
alert(a(1,2,3,4));
</script>
我想slice肯定是这种写法,arugments有length属性 也能通过var i=0;i<l;i++枚举 导致
Array.prototype.slice.call(arguments,2)运行正常 跟Array对象一样
不过一般都采用 :
Array.apply(null,arguments).slice(2)
posted on 2007-08-21 15:15 汪杰 阅读(426) 评论(4)  编辑 收藏 引用 所属分类: javascript

FeedBack:
# re: think aboust slice
2007-08-21 16:52 | 汪杰
SQL必知必会(第3版)
http://book.csdn.net/bookfiles/394/  回复  更多评论
  
# re: think aboust slice
2007-08-21 16:53 | 汪杰
一些常用SQL语句的总结 竖项变横项
http://blog.csdn.net/gsong/archive/2007/06/14/1652148.aspx  回复  更多评论
  
# re: think aboust slice
2007-11-30 09:25 | 汪杰
<script>
function test(s,e){
var temp=[];
if(e>this.length|| !e)e = this.length;
if(e<0) e = this.length + e;
if(s<0) s = this.length + s;
if(s>e) {
var stemp = e;
s = e;
e = stemp;
}
for(var i=0;i<this.length;i++)
{
if(s<=i && e>=i|| s<0)
temp.push(this[i]);
}
return temp;
}
var a="abcd";
alert(test.call(a,0));
</script>  回复  更多评论
  
# re: think aboust slice
2008-02-28 21:17 | 汪杰
<script>
Array.prototype.slice = function(s,e)
{
var ret = [];
if(!s) s = 0;
if(e > this.length || !e) e = this.length;
if(e < 0) e = this.length + e;
if(s < 0) s = this.length + s;
if(s > e){
var temp = s;
s = e;
e = s;
}
for(var i = 0, l = this.length; i < l; i++)
{
if(s <= i && e > i)
ret.push(this[i]);
}
return ret;
}
function test()
{
alert(Array.prototype.slice.apply(arguments));
}
var arr = [1,2,3,4];
alert(arr.slice(-2));
test("just"," a "," guess");
</script>  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457518
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜