Last active
June 18, 2016 16:24
-
-
Save zmts/7358d2d3234eb2fa5069618a91890ff2 to your computer and use it in GitHub Desktop.
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
// 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'); | |
}) |
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 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