Skip to content

Instantly share code, notes, and snippets.

@GHolk
Created September 20, 2017 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GHolk/e2d32c806c1b31b58f8fce5f2de74b68 to your computer and use it in GitHub Desktop.
Save GHolk/e2d32c806c1b31b58f8fce5f2de74b68 to your computer and use it in GitHub Desktop.
tamagochi prototype
var tamagotchi = {}
var action = {}
action.doNothing = function () {}
action.standBy = function () {
var date = new Date()
if (date.getMilliseconds() % 10000 == 0) {
this.say('hello master')
}
}
tamagotchi.say = function (sentence) {
alert(sentence)
}
tamagotchi.sleep = function (second) {
var originalAction = this.todo
this.todo = action.doNothing
setTimeout(() => {
this.todo = originalAction
}, second * 1000)
}
tamagotchi.todo = action.standBy
void function iterPet() {
tamagotchi.todo()
setTimeout(iterPet, 0)
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment