Skip to content

Instantly share code, notes, and snippets.

@sorie
Last active July 1, 2021 08:53
Show Gist options
  • Save sorie/cf20db57ce635c75ce57e941c23fd076 to your computer and use it in GitHub Desktop.
Save sorie/cf20db57ce635c75ce57e941c23fd076 to your computer and use it in GitHub Desktop.
promise
/**
1. 프로미스를 반환할 수도 있다.
2. then후에 반아오는 변수가 하나일 경우는 생략할 수 있다.
**/
const getHen = () =>
new Promise((resolve, reject) => {
setTimeout(() => resolve('닭'), 1000);
});
const getEgg = hen =>
new Promise((resolve, reject) => {
setTimeout(() => resolve(`${hen} => 알`), 1000);
});
get cook = egg =>
new Promise((resolve, reject) => {
setTimeout(() => resolve(`${egg} => 후라이`), 1000);
});
getHen()
.then(getEgg) //생략전 : .then(hen => getEgg(hen))
.then(cook)
.then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment