Skip to content

Instantly share code, notes, and snippets.

@BinaryMuse
Last active August 29, 2015 14:10
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 BinaryMuse/1ef56674787db244343a to your computer and use it in GitHub Desktop.
Save BinaryMuse/1ef56674787db244343a to your computer and use it in GitHub Desktop.
Add .done to native ES6 Promises
/* 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