Skip to content

Instantly share code, notes, and snippets.

@gildean
Created February 10, 2013 18:46
Show Gist options
  • Save gildean/4750579 to your computer and use it in GitHub Desktop.
Save gildean/4750579 to your computer and use it in GitHub Desktop.
a callback example
function firstFunc(somevalue, callback) {
// pass the values, error as null (no possibility of error here) and the value is the new string
// this is the normal node convention
callback(null, somevalue += ' ok');
}
// call the function with the string and an anon function that get's the values from the callback
firstFunc('this should be', function (error, callbackvalue) {
if (!error) {
// if the callback didn't pass an error, then things should be ok
console.log(callbackvalue);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment