Created
April 7, 2016 10:14
-
-
Save yakirn/9e0c00fdfa0cee196ff8d5d60501874a to your computer and use it in GitHub Desktop.
add JQuery's Promise like abilities to ES6's Promise
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
const noChange = (promise, done, fail) => { | |
promise.then(done, fail) | |
return promise | |
} | |
if(Promise.prototype.done == undefined) | |
Promise.prototype.done = function(fn){ | |
return noChange(this,fn) | |
} | |
if(Promise.prototype.fail == undefined) | |
Promise.prototype.fail = function(fn){ | |
return noChange(this, undefined, fn) | |
} | |
if(Promise.prototype.always == undefined) | |
Promise.prototype.always = function(fn){ | |
return noChange(this, fn, fn) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment