Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Created October 3, 2018 21:34
Show Gist options
  • Save eddieantonio/b7d59a757fdae339e63966d36335579a to your computer and use it in GitHub Desktop.
Save eddieantonio/b7d59a757fdae339e63966d36335579a to your computer and use it in GitHub Desktop.
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