Skip to content

Instantly share code, notes, and snippets.

@midorikocak
Created January 25, 2022 09:26
Show Gist options
  • Save midorikocak/19ca4d2144f603721c298537afdbe190 to your computer and use it in GitHub Desktop.
Save midorikocak/19ca4d2144f603721c298537afdbe190 to your computer and use it in GitHub Desktop.
Callback repeat
let songs = ["Nothing else matters", "Baby, one more time", "Laura non c'è"];
function haveAParty(musicPlayer, songs, neighborsComplained) {
if (neighborsComplained === false) {
songs.forEach((song) => {
musicPlayer(song);
});
}
}
function turnTable(song) {
console.log(`I'm playing ${song} on turn table`);
}
function cdPlayer(song) {
console.log(`I'm playing ${song} on cd player`);
}
function walkman(song) {
console.log(`I'm playing ${song} on walkman`);
}
haveAParty(turnTable, songs, true);
haveAParty(cdPlayer, songs, false);
haveAParty(walkman, songs, false);
haveAParty(
function (song) {
console.log(`I'm playing ${song} on iPod`);
},
songs,
false
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment