Skip to content

Instantly share code, notes, and snippets.

@selfish
Last active April 30, 2016 23:23
Show Gist options
  • Save selfish/b3d3f8785067b8adbc9d to your computer and use it in GitHub Desktop.
Save selfish/b3d3f8785067b8adbc9d to your computer and use it in GitHub Desktop.
Easy implementation of Promise Finally using native JS
Promise.prototype['finally'] = function finallyPolyfill(callback) {
var constructor = this.constructor;
return this.then(function(value) {
return constructor.resolve(callback()).then(function() {
return value;
});
}, function(reason) {
return constructor.resolve(callback()).then(function() {
throw reason;
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment