Use a closure with a private variable for $.cache's requests.

This commit is contained in:
Nicolas Stepien 2012-09-06 01:22:29 +02:00
parent 606875c292
commit 9f3b9a2127
2 changed files with 50 additions and 45 deletions

View File

@ -369,9 +369,11 @@
r.send(form);
return r;
},
cache: function(url, cb) {
var req, reqs, _base;
reqs = (_base = $.cache).requests || (_base.requests = {});
cache: (function() {
var reqs;
reqs = {};
return function(url, cb) {
var req;
if (req = reqs[url]) {
if (req.readyState === 4) {
cb.call(req);
@ -399,7 +401,8 @@
});
req.callbacks = [cb];
return reqs[url] = req;
},
};
})(),
cb: {
checked: function() {
$.set(this.name, this.checked);

View File

@ -295,8 +295,9 @@ $.extend $,
$.extend r.upload, upCallbacks
r.send form
r
cache: (url, cb) ->
reqs = $.cache.requests or= {}
cache: (->
reqs = {}
(url, cb) ->
if req = reqs[url]
if req.readyState is 4
cb.call req
@ -311,6 +312,7 @@ $.extend $,
onerror: -> delete reqs[url]
req.callbacks = [cb]
reqs[url] = req
)()
cb:
checked: ->
$.set @name, @checked