`
zhangyaochun
  • 浏览: 2596220 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

prototype的解读之Array

阅读更多

整理部分prototype的Array相关的api

 

1、first()

 

原api的用途

 

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

 

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

 

用例

 

 

["zhang","yao","chun"].first();   //"zhang"
[].first(); //undefined

 

源码展示:

 

 

first : function(){
   return this[0];
}

 

 

2、last()

 

原api的用途

 

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

 

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

 

用例

 

 

["zhang","yao","chun"].last();  //"chun"
[].last();  //undefined

 

源码展示:

 

 

last: function(){
    return this[this.length - 1];
}
 

3、clone()

 

原api的用途

 

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

 

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

 

 

用例

 

 

["zhang","yao","chun"].clone();  //["zhang","yao","chun"]
 

 

 

源码展示:

 

 

clone:function(){
    return [].concat(this);
}
 

 

 

 

 

1
0
分享到:
评论

相关推荐

    Javascript数组Array方法解读

    所有数组的方法都定义在Array.prototype上,而Array.prototype本身也是一个数组。 array.concat() 浅复制一份当前数组,并把接收到的参数附加到新数组的末尾。原数组不改变。 语法 array.concat(value1, value2, …,...

    prototype-1.4.0源码解读.js

    《Prototype 1.4.0 源码解读:深入理解JavaScript库的基石》 Prototype 是一个著名的JavaScript库,它的1.4.0版本在Web开发领域有着广泛的使用。这个库为JavaScript程序员提供了许多实用的功能,包括对象扩展、类...

    prototype1.4源码解读

    7. 其他实用工具:Prototype还包含了一些实用工具函数,如`Array.from()`, `String.camelize()`, `Number.toColorPart()`等,这些函数极大地提高了代码的可读性和效率。 在学习Prototype 1.4源码时,建议结合实际...

    prototype1.4

    - Prototype 1.4扩展了数组和字符串的方法,如`Array.prototype.each()`, `Array.prototype.indexOf()`, `String.prototype.startsWith()`, `String.prototype.endsWith()`等,使得处理数组和字符串变得更加方便。...

    Prototype API

    "prototype.js 1.4.0 开发笔记中文版"很可能提供了针对该版本的详细解读和开发实践,对于学习和理解Prototype API 的具体用法和最佳实践非常有帮助。 综上所述,Prototype API 和 Scriptaculous 提供了丰富的...

    prototype.js 1.4版开发者手册(强烈推荐)

    1. **对象扩展**:Prototype.js的核心在于它对JavaScript原生对象的扩展,如Array、String、Function等。例如,它增加了数组的`each`方法,使得遍历数组变得更加简洁;String类则新增了诸如`trim`和`startsWith`等...

    AJAX之Prototype入门学习.docx

    - Prototype 对 Object、Number、Function、String、Array、Event 等原生对象进行了扩展,添加了诸如 `each()`, `any()`, `collect()` 等方法,提高了代码的可读性和效率。 3. **Ajax 支持**: - `Ajax.Request` ...

    最新Prototype手册

    《最新Prototype手册》详细解读 Prototype.js 是一个广泛使用的JavaScript库,它为浏览器环境提供了许多实用的功能,大大简化了JavaScript的开发。这份“最新Prototype手册”深入探讨了这个库的核心特性,旨在帮助...

    prototype.js开发者手册.doc

    Prototype.js 包含了许多实用工具函数,例如`Object.extend`用于合并对象,`Array.clone`用于复制数组,以及`String.startsWith`和`String.endsWith`等方法,它们极大地提高了开发效率。 **与Ruby的关联** ...

    详解ECMAScript2019/ES10新属性

    Array.prototype.flat() The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. — MDN 简单来说flat这个函数就是按照一定的深度depth...

    prototype.js 1.4版开发者手册.doc

    - `$()` 函数:这是Prototype.js 最为人所知的功能之一,它是一个便捷的语法糖,用于获取DOM元素,类似于`document.getElementById()`。但它允许传入多个ID并返回一个包含所有匹配元素的数组。例如: ```html ...

    isarray-源码.rar

    return Object.prototype.toString.call(arg) === '[object Array]'; } ``` 这段代码的核心在于`Object.prototype.toString.call()`。这个方法会返回一个表示该对象的字符串。当对数组调用此方法时,它会返回`"...

    jQuery源码解读

    《jQuery源码解读:深入理解JavaScript面向对象》 在深入探讨jQuery源码之前,我们必须首先理解JavaScript中的面向对象编程概念,因为jQuery的核心机制大量运用了这一思想。面向对象编程是软件开发中的一个重要范式...

    Javascript中55个经典技巧

    18. **Set.prototype.forEach()**:遍历Set中的元素,类似于Array.prototype.forEach。 19. **Array.prototype.findIndex()**:查找元素索引,与.find()类似,但返回的是索引而非元素。 20. **Array.prototype....

    javascript(含正则表达式参考) 5.5 参考文档

    ECMAScript 5.1引入了一些新特性,如`Array.prototype.forEach`, `Array.prototype.map`, `Array.prototype.filter`等数组方法,以及`Object.create`用于创建新对象,`Object.keys`获取对象所有可枚举属性的数组,`...

Global site tag (gtag.js) - Google Analytics