prototype.js1.4版开发者手册(9)
作者:THIN 来源:cnblogs 发布时间:2007-09-30 14:09:00
标签:prototype,手册
下面代码演示如何给window添加一个load事件处理函数。
<script> Event.observe(window, ’load’, showMessage, false); function showMessage() { alert(’Page loaded.’); } </script>
在prototype.js中定义新的对象和类
另一个这个程序包帮助你的地方就是提供许多既支持面向对象设计理念又有共通功能的许多对象。
The PeriodicalExecuter object
这个对象提供一定间隔时间上重复调用一个方法的逻辑。
Method | Kind | Arguments | Description |
---|---|---|---|
[ctor](callback, interval) | callback: a parameterless function, interval: number of seconds | 创建这个对象的实例将会重复调用给定的方法。 |
Property | Type | Description |
---|---|---|
callback | 被调用的方法,该方法不能传入参数。 | |
frequency | Number | 以秒为单位的间隔。 |
currentlyExecuting | Boolean | 表示这个方法是否正在执行。 |
The Prototype object
Prototype 没有太重要的作用,只是声明了该程序包的版本 。
Property | Type | Description |
---|---|---|
Version | String | 版本。 |
emptyFunction | 空函数。 | |
K | Function(obj) | 一个仅仅回传参数的函数。 |
ScriptFragment | String | 识别script的正则式。 |
The Enumerable object
Enumberable对象能够已更优雅的方式实现对列表样式的结构进行枚举。
很多其它的对象通过扩展自Enumberable对象来得到这些有用的接口。
Method | Kind | Arguments | Description |
---|---|---|---|
each(iterator) | iterator: a function object conforming to Function(value, index) | 把每个element做为第一个参数,element的index作为第一个参数调用iterator函数。 | |
all([iterator]) | instance | iterator: a function object conforming to Function(value, index) | 这个函数会用给出的iterator测试整个集合,如果集合中任一元素在iterator函数测试中返回false或null,那么这个函数返回false,否则返回true。如果没有给出iterator,那么就会测试所有的元素是不是不等于false和null。你可以简单的把它看成是“检测每个元素都为非空非负”。 |
any(iterator) | instance | iterator: a function object conforming to Function(value, index), optional. | 这个函数会用给出的iterator测试整个集合,如果集合中任一元素在iterator函数测试中返回true,那么这个函数返回true,否则返回false。如果没有给出iterator,那么就会测试所有的元素是不是有一个不等于false和null。你可以简单的把它看成是“检测元素中是不是有非空非负的”。 |
collect(iterator) | instance | iterator: a function object conforming to Function(value, index) | 调用iterator函数根据集合中每个元素返回一个结果,然后按照原来集合中的顺序,返回一个Array。 |
detect(iterator) | instance | iterator: a function object conforming to Function(value, index) | 集合中每个元素调用一次Iterator,返回第一个使Iterator返回True的元素,如果最终都没有为true的调用,那么返回null。 |
entries() | instance | (none) | 等于toArray(). |
find(iterator) | instance | iterator: a function object conforming to Function(value, index) | 等于 detect(). |
findAll(iterator) | instance | iterator: a function object conforming to Function(value, index) | 集合中每个元素调用Iterator,返回一个由所有调用Iterator返回结果等于true的元素组成的数组。和reject()相反。 |
grep(pattern [, iterator]) | instance | pattern: a RegExp object used to match the elements, iterator: a function object conforming to Function(value, index) | 用pattern参数正则表达式测试集合中的每个元素,返回一个包含所有匹配正则式的元素的Array,如果给出了Iterator,那个每个结果还要经过一下Iterator处理。 |
include(obj) | instance | obj: any object | 判断集合中包不包含指定对象。 |
inject(initialValue, iterator) | instance | initialValue: any object to be used as the initial value, iterator: a function object conforming to Function(accumulator, value, index) | 用Iterator联接所有集合中的元素。Iterator在被调用时把上一次迭代的结果做为第一个参数传给accumulator。第一次迭代时,accurmelator等于initialValue,最后返回accumulator的值。 |
invoke(methodName [, arg1 [, arg2 [...]]]) | instance | methodName: name of the method that will be called in each element, arg1..argN: arguments that will be passed in the method invocation. | 集合中的每个元素调用指定的函数(查看源代码可以发现指定函数被调用时,this指针被传成当前元素),并传入给出的参数,返回调用结果组成的Array。 |
map(iterator) | instance | iterator: a function object conforming to Function(value, index) | 同collect() |
max([iterator]) | instance | iterator: a function object conforming to Function(value, index) | 返回集合中元素的最大值,或调用Iterator后返回值的最大值(如果给出了Iterator的话)。 |
member(obj) | instance | obj: any object | 同 include(). |
min([iterator]) | instance | iterator: a function object conforming to Function(value, index) | 返回最小值,参见max()。 |
partition([iterator]) | instance | iterator: a function object conforming to Function(value, index) | 返回一个包含两个Array的Array,第一个Array包含所有调用Iterator返回True的元素,第二个Array包含剩下的元素。如果Iterator没有给出,那么就根据元素本身判断。 |
pluck(propertyName) | instance | propertyName name of the property that will be read from each element. This can also contain the index of the element | 返回每个元素的指定属性名的属性的值组成的Array。 |
reject(iterator) | instance | iterator: a function object conforming to Function(value, index) | 和 findAll()相反(返回所有等于false的元素). |
select(iterator) | instance | iterator: a function object conforming to Function(value, index) | 同 findAll(). |
sortBy(iterator) | instance | iterator: a function object conforming to Function(value, index) | 根据每个元素调用Iterator返回的值进行排序返回一个Array。 |
toArray() | instance | (none) | 返回由集合所有元素组成的一个Array。 |
zip(collection1[, collection2 [, ... collectionN [,transform]]]) | instance | collection1 .. collectionN: enumerations that will be merged, transform: a function object conforming to Function(value, index) | 合并每个给出的集合到当前集合。合并操作返回一个新的array,这个array的元素个数和原集合的元素个数一样,这个array的每个元素又是一个子array,它合并了所有集合中相同index的元素。如果transform函数被指定,那么array的每个元素还会调用transform函数先做处理。举个例子: [1,2,3].zip([4,5,6], [7,8,9]).inspect() 返回 "[ [1,4,7],[2,5,8],[3,6,9] ]" |


猜你喜欢
- 本文实例讲述了python安装cx_Oracle模块常见问题与解决方法。分享给大家供大家参考,具体如下:安装或使用cx_Oracle时,需要
- python的pyaudio可以进行录音,播放,生成wav文件等等,WAVE是录音时用的标准的WINDOWS文件格式,文件的扩展名为WAV,
- 目录一、简单字段定义1、定义 Schema 并生成 Parquet 文件2、验证 Parquet 数据文件二、含嵌套字段定义1、验证 Par
- 看到论坛上有人模仿alert,自己也写了一个。本来想模仿winapi里的MessageBox ;但可惜js 不支持,阻塞模式。返回值只能用异
- 关于 游标 if,for 的例子 create or replace procedure peace_if is cursor var_c
- 数据结构Redis有五种基础数据结构,分别为:1、string(字符串)2、list(列表)3、hash(字典)4、set(集合)5、zse
- 1.简介和安装sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测
- 本文实例讲述了python基于右递归解决八皇后问题的方法。分享给大家供大家参考。具体分析如下:凡是线性回溯都可以归结为右递归的形式,也即是二
- 最近学习了Oracle修改字段类型方法,留做记录。有一个表名为tb,字段段名为name,数据类型nchar(20)。1、假设字段数据为空,则
- torch.nn.Modules 相当于是对网络某种层的封装,包括网络结构以及网络参数和一些操作torch.nn.Module 是所有神经网
- 1.前言这段时间,金三银四,很多人面试,很多人分享面试题。在前段时间,我也临时担任面试官,为了大概了解面试者的水平,我也写了一份题目,面试了
- 前言一段时间没有用Union和Union,再用的时候忘了怎么用了。。。所以做一篇文章来记录自己学Union和Union的经历。提前准备在Sq
- 选择了MySQL的安装版本后,要做的第二项决策是你是使用源码分发版还是二进制分发版。大多数情况,如果你的平台上已经有了一个二进制分发版,你可
- 1.前言:将测试数据全部敲入数据库非常繁琐,而且如果与合作伙伴一起开发,部署,那么他们肯定也不想把时间花在一个一个录入数据的繁琐过程中,这时
- 实例如下所示:#########start 获取文件路径、文件名、后缀名############def jwkj_get_filePath_
- 前言我们经常需要将大量数据保存起来以备后续使用,数据库是一个很好的解决方案。在众多数据库中,MySQL数据库算是入门比较简单、语法比较简单,
- 本文实例讲述了Sanic框架Cookies操作。分享给大家供大家参考,具体如下:简介Sanic是一个类似Flask的Python 3.5+
- 因为需要对数据处理,将excel数据导入到数据库,记录一下过程。使用到的库:xlrd 和 pymysql (如果需要写到excel可以使用x
- 接着python里面的xlrd模块详解(一)中我们我们来举一个实例:我们来举一个从Excel中读取账号和密码的例子并调用:&diam
- 1. 现在的日期时间命令是<%=now%> 即可2.ASP取得表格(from)数据输入的方法,是使用一个内置