Skip to content

Instantly share code, notes, and snippets.

@fxm90
Created February 28, 2017 14:27
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 fxm90/2721609765dbe56216fb20d6ac8c65ce to your computer and use it in GitHub Desktop.
Save fxm90/2721609765dbe56216fb20d6ac8c65ce to your computer and use it in GitHub Desktop.
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