prototype.js 1.5

$()函数:

    document.getElementById()的替代品,支持多个参数,能使用元素Id或元素本身

$F()函数

    获取表单中text box, drop-down list的值,能使用元素Id或元素本身

$A()函数

   把接收到的单个参数转化为一个Array对象

$H()函数

   把一些对象转化成一个可以枚举的和联合数组类似的Hash对象

$R()参数

    获取一系列值。是new ObjectRange(lowBound,upperBound,excludeBounds)的缩写

Try.these()函数

    调用直到一个成功。

-----------------------------

Event扩展
Property Type Description
KEY_BACKSPACE NumberNumber 8: Constant. Code for the Backspace key.
KEY_TAB Number 9: Constant. Code for the Tab key.
KEY_RETURN Number 13: Constant. Code for the Return key.
KEY_ESC Number 27: Constant. Code for the Esc key.
KEY_LEFT Number 37: Constant. Code for the Left arrow key.
KEY_UP Number 38: Constant. Code for the Up arrow key.
KEY_RIGHT Number 39: Constant. Code for the Right arrow key.
KEY_DOWN Number 40: Constant. Code for the Down arrow key.
KEY_DELETE Number 46: Constant. Code for the Delete key.
observers: Array List of cached observers. Part of the internal implementation details of the object.

Method Kind Arguments Description
element(event) static event: an Event object 返回事件源对象。
isLeftClick(event) static event: an Event object 如果点击了鼠标左键,返回true.
pointerX(event) static event: an Event object 返回鼠标的X座标。 
pointerY(event) static event: an Event object 返回鼠标的Y座标。
stop(event) static event: an Event object 使用此函数来中断事件的默认行为并阻止传递(冒泡)。
findElement(event, tagName) static event: an Event object, tagName: name of the desired tag. 从事件源对象开始向上搜索DOM树,直到找到第一个符合tagName的元素
observe(element, name, observer, useCapture) static element: object or id, name: event name (like 'click', 'load', etc), observer: function to handle the event, useCapture: if true, handles the event in the capture phase and if false in the bubbling phase. 为对象的某个事件增加一个处理函数。
stopObserving(element, name, observer, useCapture) static element: object or id, name: event name (like 'click'), observer: function that is handling the event, useCapture: if true handles the event in the capture phase and if false in the bubbling phase. 和上面的函数相反。
_observeAndCache(element, name, observer, useCapture) static   私有函数,别管它。
unloadCache() static (none) 私有函数,别管它。从内存中清除所有的observers缓存

The PeriodicalExecuter object
这个对象提供一定间隔时间上重复调用一个方法的逻辑。

Method Kind Arguments Description
[ctor](callback, interval) constructor callback: a parameterless function, interval: number of seconds 创建这个对象的实例将会重复调用给定的方法。


Property Type Description
callback Function() 被调用的方法,该方法不能传入参数。
frequency Number 以秒为单位的间隔。
currentlyExecuting Boolean 表示这个方法是否正在执行。

 

The Prototype object
Prototype 没有太重要的作用,只是声明了该程序包的版本 。

Property Type Description
Version String 版本。
emptyFunction Function() 空函数。
K Function(obj) 一个仅仅回传参数的函数。
ScriptFragment String 识别script的正则式。

 

The Enumerable object
Enumberable对象能够已更优雅的方式实现对列表样式的结构进行枚举。

很多其它的对象通过扩展自Enumberable对象来得到这些有用的接口。

Method Kind Arguments Description
each(iterator) instance 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] ]" 

 

The Hash object
 Hash对象实现一种Hash结构,也就是一个Key:Value对的集合。

Hash中的每个Item是一个有两个元素的array,前一个是Key,后一个是Value,每个Item也有两个不需加以说明的属性,key和value。

Method Kind Arguments Description
keys() instance (none) 返回所有Item的key的集合的一个array。 
values() instance (none) 返回所有Item的value的集合的一个array。 
merge(otherHash) instance otherHash: Hash object 合并给出的Hash,返回一个新Hash。 
toQueryString() instance (none) 以QueryString那样的样式返回hash中所有的item,例如: 'key1=value1&key2=value2&key3=value3' 
inspect() instance (none) 用一种合适的方法显示hash中的key:value对。

 

The ObjectRange class
继承自  Enumerable

用上、下边界描述一个对象区域。

Property Type Kind Description
start (any) instance range的下边界
 
end (any) instance range的上边界
exclusive Boolean instance 决定边界自身是不是range的一部分。


Method Kind Arguments Description
[ctor](start, end, exclusive) constructor start: the lower bound, end: the upper bound, exclusive: include the bounds in the range? 创建一个range对象,从start生成到end,这里要注意的是,start和end必段类型一致,而且该类型要有succ()方法。 
include(searchedValue) instance searchedValue: value that we are looking for 检查一个value是不是在range中。 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值