Last active
August 29, 2015 13:57
-
-
Save keriati/9618187 to your computer and use it in GitHub Desktop.
Callback hell solutions
This file contains 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
var AwesomeObject = function() {}; | |
AwesomeObject.prototype = { | |
doSomeThingAsync: function() { | |
var that = this; | |
// Do that with bind? | |
return asyncThing({ | |
success: function() { that.onSuccess.apply(that, arguments);}, | |
error: function() { that.onError.apply(that, arguments);}, | |
complete: function() { that.onComplete.apply(that, arguments);} | |
}) | |
}, | |
onSuccess: function() { | |
this.happy(); | |
}, | |
onError: function() { | |
this.sad(); | |
}, | |
onComplete: function() { | |
this.whatever(); | |
}, | |
happy: function() { console.log('happy'); }, | |
sad: function() { console.log('sad'); }, | |
whatever: function() { console.log('whatever'); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment