Skip to content

Instantly share code, notes, and snippets.

@keriati
Last active August 29, 2015 13:57
Show Gist options
  • Save keriati/9618187 to your computer and use it in GitHub Desktop.
Save keriati/9618187 to your computer and use it in GitHub Desktop.
Callback hell solutions
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