Skip to content

Instantly share code, notes, and snippets.

@bajpaik
Forked from prof3ssorSt3v3/callback-functions.js
Created May 26, 2019 13:37
Show Gist options
  • Save bajpaik/1c0b1865513f7a493a52bbe7e368607e to your computer and use it in GitHub Desktop.
Save bajpaik/1c0b1865513f7a493a52bbe7e368607e to your computer and use it in GitHub Desktop.
// Callback functions
//built-in callback functions
//setTimeout, Arr.forEach, geolocation.getCurrentPosition
//make your own callback functions
//setTimeout( hello, 2000, 'Bob')
let names = ['Inga','Tom','Mattias','Carlos'];
names.forEach(hello);
navigator.geolocation.getCurrentPosition(gotPosition, positionError, {});
function gotPosition(pos){
}
function positionError(err){
}
function doThing(other){
let x = 7;
//do lots of other things
//...
let name = 'Steve';
other(name);
}
function hello(nm, idx, arr){
console.log('hello', nm);
}
/**
doThing(hello);
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment