Skip to content

Instantly share code, notes, and snippets.

@siffring
Created October 7, 2011 18:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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