Skip to content

Instantly share code, notes, and snippets.

@dnasca
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save dnasca/2e0c07b67eeb2102c791 to your computer and use it in GitHub Desktop.

Select an option

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.
/*
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