开发者

Simulate AJAX latency with a wrapping closure

开发者 https://www.devze.com 2023-01-10 08:06 出处:网络
I\'d like to wrap Prototype Ajax.Request in order to simulate AJAX latency. I mean, using a closure and Prototype\'s delay() facility, but apparently there is something wrong with my code

I'd like to wrap Prototype Ajax.Request in order to simulate AJAX latency. I mean, using a closure and Prototype's delay() facility, but apparently there is something wrong with my code

/*
 * Purpose: sim开发者_StackOverflow中文版ulate AJAX latency when developing on localhost
 * What's wrong?
 */
Ajax.Request = (function(original) {
  return function(url, options) {
          return original.delay(1, url, options);
  };
}) (Ajax.Request);


This worked for me (using prototype 1.6.1):

Ajax.Request.prototype._initialize = Ajax.Request.prototype.initialize;

Ajax.Request.prototype.initialize = function ($super, url, options) {
  return this._initialize.bind(this).delay(2, $super, url, options);
};

I believe the method signature for Ajax.Request.prototype.initialize is different in older version of prototype (i.e. without the $super parameter).

This will update it for all Ajax requests though.

0

精彩评论

暂无评论...
验证码 换一张
取 消