Created
October 1, 2014 14:25
-
-
Save Riduidel/ac6f3c26f32be6d15ed6 to your computer and use it in GitHub Desktop.
Un Deferred qu'on peut réexcuter quand on veut
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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