Skip to content

Instantly share code, notes, and snippets.

@kumavis
Last active December 5, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumavis/0e0893459c690edd09a3221ace0af5d0 to your computer and use it in GitHub Desktop.
Save kumavis/0e0893459c690edd09a3221ace0af5d0 to your computer and use it in GitHub Desktop.
_then = Promise.prototype.then
// [Function: then]
Promise.prototype.then = function(){ console.log('then!'); return _then.apply(this, arguments); }
// [Function (anonymous)]
p = new Promise(resolve => resolve())
// Promise { undefined }
p.then()
// then!
// Promise { <pending> }
(async function () { await Promise.resolve(1) })()
// Promise { <pending> }
(async function () { await new Promise(resolve => resolve()) })()
// Promise { <pending> }
x = { then: (fn) => { console.log('thennable!'); fn() } }
// { then: [Function: then] }
(async function () { await x })()
// Promise { <pending> }
// thennable!
@kumavis
Copy link
Author

kumavis commented Dec 5, 2019

node v13.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment