网络编程
位置:首页>> 网络编程>> JavaScript>> prototype.js1.4版开发者手册(10)

prototype.js1.4版开发者手册(10)

作者:THIN 来源:cnblogs 发布时间:2007-09-30 14:09:00 

标签:prototype,手册

The Hash object

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

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


MethodKindArgumentsDescription
keys()instance(none)返回所有Item的key的集合的一个array。
values()
(none)返回所有Item的value的集合的一个array。
merge(otherHash)instanceotherHash: 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

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


PropertyTypeKindDescription
start(any)

range的下边界

end(any)instancerange的上边界
exclusiveBooleaninstance决定边界自身是不是range的一部分。



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



The Class object

在这个程序包中 Class 对象在声明其他的类时候被用到 。用这个对象声明类使得新类支持 initialize() 方法,他起构造方法的作用。

看下面的例子


//declaring the class
var MySampleClass = Class.create();


//defining the rest of the class implmentation
MySampleClass.prototype = {
   initialize: function(message) {
this.message = message;
   },
   showMessage: function(ajaxResponse) {
      alert(this.message);
   }
};
//now, let’s instantiate and use one object
var myTalker = new MySampleClass(’hi there.’);
myTalker.showMessage(); //displays alert



MethodKindArgumentsDescription
create(*)
(any)定义新类的构造方法。



The Ajax object

这个对象被用作其他提供AJAX功能的类的根对象。 


PropertyTypeKindDescription
activeRequestCountNumberinstance正在处理中的Ajax请求的个数。



MethodKindArgumentsDescription
getTransport()
(none)返回新的XMLHttpRequest 对象。



The Ajax.Responders object

继承自 Enumerable

这个对象维持一个在Ajax相关事件发生时将被调用的对象的列表。比如,你要设置一个全局钩子来处理Ajax操作异常,那么你就可以使用这个对象。


PropertyTypeKindDescription
respondersArray
被注册到Ajax事件通知的对象列表。



MethodKindArgumentsDescription
register(responderToAdd)instanceresponderToAdd: object with methods that will be called.被传入参数的对象应包含名如Ajax事件的系列方法(如onCreate,onComplete,onException)。通讯事件引发所有被注册的对象的合适名称的函数被调用。
unregister(responderToRemove)instanceresponderToRemove: object to be removed from the list. 从列表中移除。
dispatch(callback, request, transport, json)instancecallback: name of the AJAX event being reported, request: the Ajax.Request object responsible for the event, transport: the XMLHttpRequest object that carried (or is carrying) the AJAX call, json: the X-JSON header of the response (if present)遍历被注册的对象列表,找出有由callback参数决定的那个函数的对象。然后向这些函数传递其它的三个参数,如果Ajax响应中包含一个含有JSON内容的X-JSON HTTP头,那么它会被热行并传入json参数。如果事件是onException,那么transport参数会被异常代替,json不会传递。


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com