JavaScript 내부 체인의 프로미스

체인 함수는 프로미스도 반환할 수 있습니다. 이 경우 해당 프로미스의 결과는 다음 then으로 전달됩니다:

javascriptpromise.then(
  function(result) {
    return result + '1';
  }
).then(
  function(result) {
    return new Promise(function(resolve) {
      resolve(result + '2'); // 이 결과는 다음 then으로 전달됨
    });
  }
).then(
  function(result) {
    return result + '3';
  }
).then(
  function(result) {
    console.log(result); // 'string123'을 출력함
  }
);