Created
June 22, 2012 20:44
-
-
Save togakangaroo/2975072 to your computer and use it in GitHub Desktop.
I guess its my turn to write a flow control library
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
### | |
My tiny little flow control library. | |
Usage: | |
$.Deferred.invoke func, context, ...args | |
func - Function with its two final parameters being onSuccess and onError | |
context - context to bind to 'this' when func is invoked | |
args - flat list of arguments | |
Returns: | |
jQuery Deferred object | |
gettingFs = $.Deferred.invoke(window.requestFileSystem, window, TEMPORARY, 0); | |
gettingFs.done(function(fileSystem) {console.log("ok", fileSystem) }); | |
gettingFs.error(function(err){console.log("error", err)}); | |
### | |
slice = Array.prototype.slice | |
$.extend $.Deferred, | |
invoke: (func,ctx) -> | |
args = slice.call arguments, 2 | |
$.Deferred (d) -> | |
args.push -> d.resolve.apply d, arguments | |
args.push -> d.reject.apply d, arguments | |
func.apply ctx, args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment