Created
October 7, 2011 18:14
-
-
Save siffring/1270986 to your computer and use it in GitHub Desktop.
Javascript: pass a function as a parameter to another function
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
// pass a function as a parameter of another function | |
function doAnotherThing() { | |
console.log('Doing another thing…'); | |
} | |
function doSomething(callback) { | |
console.log('Doing something…'); | |
if (typeof callback == 'function') { | |
callback.call(); | |
} | |
} | |
doSomething(doAnotherThing); | |
// results in: | |
// Doing something… | |
// Doing another thing… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment