Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created October 1, 2014 14:25
Show Gist options
  • Select an option

  • Save Riduidel/ac6f3c26f32be6d15ed6 to your computer and use it in GitHub Desktop.

Select an option

Save Riduidel/ac6f3c26f32be6d15ed6 to your computer and use it in GitHub Desktop.
Un Deferred qu'on peut réexcuter quand on veut
define(["jquery"], function($) {
function ReinvokableDeferred() {
this.success = [];
this.failure = [];
this.any = [];
}
ReinvokableDeferred.prototype = {
_add : function(array, called) {
for(var arg in called) {
array.push(called[arg]);
}
},
then : function() {
this._add(this.success, arguments);
},
done : function() {
this._add(this.success, arguments);
},
fail : function() {
this._add(this.failure, arguments);
},
always : function() {
this._add(this.any, arguments);
},
deferred : function() {
var returned = $.Deferred();
returned.done.call(returned, this.success);
returned.fail.call(returned, this.failure);
returned.always.call(returned, this.any);
return returned;
}
};
return ReinvokableDeferred;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment