Skip to content

Instantly share code, notes, and snippets.

@fxm90 fxm90/Deferred.js
Created Feb 28, 2017

Embed
What would you like to do?
Create a angular like deferred object with plain javascript (ES6)
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
You can’t perform that action at this time.