Created
October 28, 2011 15:54
-
-
Save Slicertje/1322603 to your computer and use it in GitHub Desktop.
Detect if callback is called
This file contains 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 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