Skip to content

Instantly share code, notes, and snippets.

@Slicertje
Created October 28, 2011 15:54
Show Gist options
  • Save Slicertje/1322603 to your computer and use it in GitHub Desktop.
Save Slicertje/1322603 to your computer and use it in GitHub Desktop.
Detect if callback is called
function doTest (callback) {
var isCallbackCalled = false;
var successCallback = function () {
isCallbackCalled = true;
};
callback.apply(null, [ successCallback ]);
if (isCallbackCalled) {
alert('Callback called');
}
else {
alert('Callback not called');
}
}
doTest(function (callback) {
alert('Test 1, callback called!');
callback();
});
doTest(function(callback) {
alert('Test 2, callback not called');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment