Skip to content

Instantly share code, notes, and snippets.

@zmts
Last active June 18, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmts/7358d2d3234eb2fa5069618a91890ff2 to your computer and use it in GitHub Desktop.
Save zmts/7358d2d3234eb2fa5069618a91890ff2 to your computer and use it in GitHub Desktop.
// define function with two args and callback
function foo(a, b, cb) {
console.log(a + ' ' + b);
// check type of cb
if (typeof(cb) === "function") {
cb();
}
else {
console.log('error ' + cb + ' not a function');
}
};
// execute function
foo('cat', 'dog', function() {
console.log('hello');
})
function foo(firstName, secondName, cb) {
var fullName = firstName + ' ' + secondName;
if (typeof(cb) === "function") {
cb(fullName);
}
else {
console.log('error ' + cb + ' not a function');
}
}
foo('Alex', 'Born', function(takenFromCb) {
console.log(takenFromCb.toUpperCase());
})
// >> ALEX BORN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment