Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created January 21, 2018 20:47
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 uno-de-piera/887abc9e1495c2ca01c15de78cc492a0 to your computer and use it in GitHub Desktop.
Save uno-de-piera/887abc9e1495c2ca01c15de78cc492a0 to your computer and use it in GitHub Desktop.
export class User {
userPromise() {
return new Promise((resolve, reject) => {
if(1 === 1) {
return resolve([{name: 'Iparra'}])
}
return reject({msg: 'error'});
})
}
}
let user = new User();
let promise = user.getUserPromise();
promise.then(user => {
console.log(user[0]); //{name: 'Iparra'}
}).catch(error => {
console.log(error); //Uncaught {msg: "error"}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment