Promise then

7호선개발자·2020년 5월 3일
0

function getData() {
return new Promise(function(resolve, reject) {
$.get({
url: "https://api.hnpwa.com/v0/news/1.json",
success: function(data) {
resolve(data);
},
});
});
}

  getData()
    .then(test1)
    .then(test2)
    .then(test3);

  function test1(data) {
    return new Promise((resolve) => {
      console.log(data);
      resolve(data);
    });
  }

  function test2(data) {
    const arr = [];
    return new Promise((resolve) => {
      for (const i in data) {
        arr.push(data[i].title);
      }
      resolve(arr);
    });
  }

  function test3(data) {
    console.log(data);
  }
profile
안녕하세요

0개의 댓글