Last active
December 17, 2015 08:18
-
-
Save adamstrickland/5578805 to your computer and use it in GitHub Desktop.
jquery callback
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
MyObject = { | |
respondToCallback: function (response, context) { | |
// context will === "abc123" when called via doingSomething() | |
}, | |
doingSomething: function(callback) { | |
var _foo = "abc123"; | |
var _self = this; | |
var _default_callback = function (resp, status, jqxhr) { | |
_self.respondToCallback(response, _foo); | |
}; | |
var _callback = callback || _default_callback; | |
$.getJSON(_url, _params, _callback); | |
} | |
}; |
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
function MyObject (initializer_params) { | |
var self = this; | |
self.respondToCallback = function (resp, ctx) { ... }; | |
self.doingSomething = function (callback) { | |
... | |
var _default_callback = function (r, s, x) { | |
self.respondToCallback(r, _foo); | |
}; | |
... | |
}; | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment