Last active
August 29, 2015 14:10
-
-
Save BinaryMuse/1ef56674787db244343a to your computer and use it in GitHub Desktop.
Add .done to native ES6 Promises
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
/* Native HTML5 promises will swallow exceptions if you're not careful. For example: | |
* | |
* promise.then(function() { | |
* something.froEach(iterator); | |
* }); | |
* | |
* This extension patches the Promise prototype with a `done` method that will log errors: | |
* | |
* promise.then(function() { | |
* something.froEach(iterator); | |
* }).done(); | |
*/ | |
define(function() { | |
if (window.Promise.prototype.done) { | |
console.warn("WARNING: not monkey-patching Promise.done as it already exists"); | |
} else { | |
window.Promise.prototype.done = function() { | |
this.then(null, function(e) { | |
console.error(e.stack); | |
}); | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment