Last active
August 29, 2015 14:26
-
-
Save dnasca/2e0c07b67eeb2102c791 to your computer and use it in GitHub Desktop.
Pattern: the synchronous callback -- the callback that is called at the same time [in the same processing cycle] that the function is called.
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
| /* | |
| the synchronous callback: | |
| create a function that can be called at a later time whenever the | |
| higher order function (the function that were passing this function into -- aka: the function doing the calling) | |
| is ready to call/invoke this function. Read this a few times and it will eventually make sense :) | |
| */ | |
| whenDone = function () { | |
| console.log ("done") | |
| }; | |
| doWork = function(callback) { | |
| //do some work | |
| callback(); //the synchronous call - note: in an asynchronous call, this would be called at a later time | |
| }; | |
| //call doWork(whenDone) //output: "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment