Created
September 20, 2017 16:49
-
-
Save GHolk/e2d32c806c1b31b58f8fce5f2de74b68 to your computer and use it in GitHub Desktop.
tamagochi prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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