Created
February 16, 2015 23:57
-
-
Save bengl/1ef29476292f656b5a6c to your computer and use it in GitHub Desktop.
You can't extend promises in node 0.12.0
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
function ExtendedPromise (resolver) { | |
Promise.call(this, resolver) | |
} | |
require('util').inherits(ExtendedPromise, Promise) | |
ExtendedPromise.__proto__ = Promise | |
new ExtendedPromise(function (resolve) { | |
resolve(1) | |
}).then(console.log) |
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
$ node extendedpromise.js | |
/Users/benglish/extendedpromise.js:2 | |
Promise.call(this, resolver) | |
^ | |
TypeError: #<ExtendedPromise> is not a promise | |
at new ExtendedPromise (/Users/benglish/extendedpromise.js:2:11) | |
at Object.<anonymous> (/Users/benglish/extendedpromise.js:8:5) | |
at Module._compile (module.js:460:26) | |
at Object.Module._extensions..js (module.js:478:10) | |
at Module.load (module.js:355:32) | |
at Function.Module._load (module.js:310:12) | |
at Function.Module.runMain (module.js:501:10) | |
at startup (node.js:129:16) | |
at node.js:814:3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the iojs ES6 version of this seems to work: