Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@w0rm
Forked from keriati/callbackhell.js
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save w0rm/9618351 to your computer and use it in GitHub Desktop.
Save w0rm/9618351 to your computer and use it in GitHub Desktop.
var AwesomeObject = function() {
this.init()
};
AwesomeObject.prototype = {
init: function() {
_.bindAll(this, 'onSuccess', 'onError', 'onComplete')
// or
this.onSuccess = $.proxy(this.onSuccess, this)
this.onError = $.proxy(this.onError, this)
this.onComplete = $.proxy(this.onComplete, this)
// or
this.onSuccess = this.onSuccess.bind(this)
this.onError = this.onError.bind(this)
this.onComplete = this.onComplete.bind(this)
},
doSomeThingAsync: function() {
return asyncThing({
success: this.onSuccess,
error: this.onError,
complete: this.onComplete
})
},
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'); }
}
@keriati
Copy link

keriati commented Mar 18, 2014

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment