【问题标题】:Simulate AJAX latency with a wrapping closure使用包装闭包模拟 AJAX 延迟
【发布时间】:2010-08-04 08:55:03
【问题描述】:

我想包装 Prototype Ajax.Request 以模拟 AJAX 延迟。我的意思是,使用闭包和 Prototype 的 delay() 工具,但显然我的代码有问题

/*
 * Purpose: simulate 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);

【问题讨论】:

    标签: javascript ajax prototypejs closures latency


    【解决方案1】:

    这对我有用(使用原型 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);
    };
    

    我相信 Ajax.Request.prototype.initialize 的方法签名在旧版本的原型中是不同的(即没有 $super 参数)。

    这将为所有 Ajax 请求更新它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2010-10-11
      • 2023-01-25
      相关资源
      最近更新 更多