Skip to content

Instantly share code, notes, and snippets.

@siffring
Created October 7, 2011 18:14
Show Gist options
  • Save siffring/1270986 to your computer and use it in GitHub Desktop.
Save siffring/1270986 to your computer and use it in GitHub Desktop.
Javascript: pass a function as a parameter to another function
// 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