Skip to content

Instantly share code, notes, and snippets.

@milleraundra
Created January 12, 2021 05:20
Show Gist options
  • Save milleraundra/6e1a4847eb8d8b8d97e08b7832b742eb to your computer and use it in GitHub Desktop.
Save milleraundra/6e1a4847eb8d8b8d97e08b7832b742eb to your computer and use it in GitHub Desktop.
Last Christmas by WHAM! as a recursive function
ChristmasThisYear(new Lover(), new Heart());
function ChristmasThisYear(baby, heart) {
baby.give(heart)
.catch((veryNextDay) => {
if (veryNextDay === 'Gave it away') {
let someoneSpecial = new Lover();
return ChristmasThisYear(someoneSpecial, heart);
// return tears
}
});
}
class Heart {
giveAway() {
return 'Gave it away'
};
}
class Lover {
give(heart) {
return new Promise((resolve, reject) => {
reject(heart.giveAway());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment