편집 기록

편집 기록
  • 프로필 편집요청빌런님의 편집
    날짜2020.04.02

    자바스크립트 promise 관련 질문입니다.


    function delay(a) {
        setTimeout(() => {
            console.log(a);
        }, 1000);
    }
    
    function prompt(a) {
        console.log(a);
    }
    
    var temp = function() {
        return new Promise((resolve) => {
            delay('first');
            resolve();
        });
    };
    
    temp().then(() => {
        prompt('second');
    });
    

    first, second 순으로 출력하려고 하는데,

    second 부터 출력이됩니다.

    delay(), promt() 함수를 수정하지 않고 first second 순으로 출력할 수 있을까요?

  • 프로필 조영민님의 편집
    날짜2020.04.02

    자바스크립트 promise 관련 질문입니다.


    function delay(a){
        setTimeout(() => {
            console.log(a)
        }, 1000);
    }
    
    
    function prompt(a){
        console.log(a)
    }
    
    
    
    var temp = function(){
        return new Promise((resolve)=>{
            delay('first')
            resolve()
        })
    }
    
    temp().then(()=>{
        prompt('second')
    })
    
    
    

    first, second 순으로 출력하려고 하는데,

    second 부터 출력이됩니다.

    delay() promt() 함수를 수정하지 않고 first second 순으로 출력할 수 있을까요?