Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Last active January 13, 2023 23:52
Show Gist options
  • Save Slackwise/6c469b0fbe99ff205a649f2b401294a5 to your computer and use it in GitHub Desktop.
Save Slackwise/6c469b0fbe99ff205a649f2b401294a5 to your computer and use it in GitHub Desktop.
Function definition modeling Schrodinger's Cat.
const cat = {
get state() {
delete this.state;
this.state = Math.random() >= 0.5 ? 'Alive' : 'Dead';
return this.state;
}
};
cat.state; // "Quantum Wavefunction Collapse" - the function replaces itself with the result of its computation
cat.state; // All future calls will return a static value and not a function
cat.state;
cat.state;
cat.state;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment