Chinaunix首页 | 论坛 | 博客
  • 博客访问: 860717
  • 博文数量: 366
  • 博客积分: 10267
  • 博客等级: 上将
  • 技术积分: 4290
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:04
文章分类

全部博文(366)

文章存档

2012年(366)

分类: 系统运维

2012-03-12 19:07:15

整理部分prototype的Array相关的api

1、first()

原api的用途

Returns the first item in the array,or undefined if the array is empty.

返回数组的第一项或者当数组为空时,返回undefined

用例

Js代码 复制代码 收藏代码
  1. ["zhang","yao","chun"].first(); //"zhang"
  2. [].first(); //undefined
["zhang","yao","chun"].first(); //"zhang"[].first(); //undefined

源码展示:

Js代码 复制代码 收藏代码
  1. first : function(){
  2. return this[0];
  3. }
first : function(){ return this[0];}

2、last()

原api的用途

Returns the last item in the array,or undefined if the array is empty.

返回数组的最后一项,或者当数组为空时,返回undefined

用例

Js代码 复制代码 收藏代码
  1. ["zhang","yao","chun"].last(); //"chun"
  2. [].last(); //undefined
["zhang","yao","chun"].last(); //"chun"[].last(); //undefined

源码展示:

Js代码 复制代码 收藏代码
  1. last: function(){
  2. return this[this.length - 1];
  3. }
last: function(){ return this[this.length - 1];}

3、clone()

原api的用途

Returns a duplicate of the array,leaving the original array intact.

返回原来数组的复制,原来那个数组没有任何变化。

用例

Js代码 复制代码 收藏代码
  1. ["zhang","yao","chun"].clone(); //["zhang","yao","chun"]
["zhang","yao","chun"].clone(); //["zhang","yao","chun"]

源码展示:

Js代码 复制代码 收藏代码
  1. clone:function(){
  2. return [].concat(this);
  3. }
clone:function(){ return [].concat(this);}
阅读(349) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~