Created
March 28, 2012 12:36
-
-
Save leecrossley/2225824 to your computer and use it in GitHub Desktop.
Panda: without context splurge, callbacks or base library.
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 panda = (function () { | |
var panda = {}, bambooLevel = 0, isAsleep = false; | |
function wakeUp() { | |
isAsleep = false; | |
} | |
panda.eatBamboo = function () { | |
bambooLevel = bambooLevel + 1; | |
}; | |
panda.goToSleep = function () { | |
isAsleep = true; | |
setTimeout(wakeUp, 1000); | |
}; | |
return panda; | |
})(); | |
panda.eatBamboo(); | |
panda.goToSleep(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you wanted to, instead of declaring "isAsleep" as a local variable, you could do panda.isAsleep is make it accessible outside in the wild. I've kept it in it's cage though.