Created
October 3, 2018 21:34
-
-
Save eddieantonio/b7d59a757fdae339e63966d36335579a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Duration { | |
constructor(number) { | |
this._number = number; | |
} | |
valueOf() { | |
return this._number; | |
} | |
then(fn) { | |
setTimeout(fn, this.valueOf()); | |
} | |
} | |
Object.defineProperty(Number.prototype, 'seconds', { | |
enumerable: false, | |
get() { | |
return new Duration(this * 1000); | |
} | |
}); | |
console.log('Now'); | |
setTimeout(_ => console.log('2 seconds later'), (2).seconds); | |
(async function doIt() { | |
await (2).seconds; | |
console.log('2 seconds later'); | |
})(); | |
/*eslint no-console: 0*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment