Created
February 28, 2017 14:27
-
-
Save fxm90/2721609765dbe56216fb20d6ac8c65ce to your computer and use it in GitHub Desktop.
Create a angular like deferred object with plain javascript (ES6)
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
class Deferred { | |
constructor() { | |
this.promise = new Promise((resolve, reject) => { | |
this.reject = reject; | |
this.resolve = resolve; | |
}); | |
} | |
resolve(value) { | |
this.resolve(value); | |
} | |
reject(reason) { | |
this.reject(reason); | |
} | |
then(...args) { | |
return this.promise.then(...args); | |
} | |
catch(...args) { | |
return this.promise.catch(...args); | |
} | |
} | |
export default Deferred; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment