Skip to content

Instantly share code, notes, and snippets.

@ohoroyoi
Last active July 13, 2019 15:53
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 ohoroyoi/4c50cc141f7f68ac2526303bc5b18a9a to your computer and use it in GitHub Desktop.
Save ohoroyoi/4c50cc141f7f68ac2526303bc5b18a9a to your computer and use it in GitHub Desktop.
출력결과가 어떻게 될까요
// const todosPromise = new Promise((resolve, reject) => {
// const condition = Math.random() > 0.5; //true or false
// return condition ? resolve('성공했어요') : reject('실패했어용');
// });
// // console.log(todosPromise);
// todosPromise.then((data) => {
// console.log(data);
// }).catch((err)=>{
// console.log(err);
// });
const getTodos = (id) => {
return new Promise((resolve, reject) => {
$.getJSON(`https://jsonplaceholder.typicode.com/todos/${id}`, (data) => {
resolve(data);
});
});
}
console.log("하나");
getTodos('1')
.then((data) => {
console.log(data);
console.log("둘");
return getTodos('2');
}).then((data2) => {
console.log(data2);
return getTodos('3');
}).then((data3)=>{
console.log(data3);
return getTodos('4');
}).then((data4) => {
console.log(data4);
}).catch((err) => {console.log(err)});
console.log("셋");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment