Skip to content

Instantly share code, notes, and snippets.

@w0rm
Forked from keriati/callbackhell.js
Last active August 29, 2015 13:57

Revisions

  1. w0rm revised this gist Mar 18, 2014. 1 changed file with 20 additions and 7 deletions.
    27 changes: 20 additions & 7 deletions callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,28 @@
    var AwesomeObject = function() {};
    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() {
    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);}
    success: this.onSuccess,
    error: this.onError,
    complete: this.onComplete
    })

    },
  2. @keriati keriati revised this gist Mar 18, 2014. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -15,14 +15,18 @@ AwesomeObject.prototype = {
    },

    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'); }
    }
  3. @keriati keriati revised this gist Mar 18, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    var myObject = {
    var AwesomeObject = function() {};

    AwesomeObject.prototype = {

    doSomeThingAsync: function() {
    var that = this;
  4. @keriati keriati revised this gist Mar 18, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ var myObject = {
    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);},
  5. @keriati keriati revised this gist Mar 18, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    var myObject = {

    doSomeThingAsync: function() {
    var that = this;

    return asyncThing({
    success: function() { that.onSuccess.apply(that, arguments);},
  6. @keriati keriati created this gist Mar 18, 2014.
    24 changes: 24 additions & 0 deletions callbackhell.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var myObject = {

    doSomeThingAsync: function() {

    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() {

    },

    onError: function() {

    },

    onComplete: function() {

    }
    }