Created
February 10, 2013 18:46
-
-
Save gildean/4750579 to your computer and use it in GitHub Desktop.
a callback example
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 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