Created
August 21, 2015 00:13
-
-
Save InfamousVague/8a5982a78c39edc96584 to your computer and use it in GitHub Desktop.
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
let timebomb = { | |
wires: function() { | |
Object.observe(this, (changes) => { | |
// It's the blue wire. | |
if(change.name !== 'defuse') this.charge(); | |
}); | |
}, | |
clock: null, | |
charge: null, | |
defuse: function(){ | |
clearTimeout(this.clock); | |
}, | |
arm: function(time, callback) { | |
this.defuse = callback; | |
this.clock = setTimeout(callback, time); | |
} | |
}; | |
// Usage: | |
setTimeout(()=>{ | |
timebomb.arm(3000, ()=>{ | |
console.log('boom!'); | |
}); | |
timebomb.defuse(); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment