[Javascript] 콜백 패턴 vs 프라미스 패턴

박성찬·2021년 5월 22일
0

1. 콜백 패턴 (Call Back Pattern)

var callBack = function(text, done){
  console.log('callBackkFunc', text);
  done(text + ' done');
}
 
callBack('test Text', function(res){ 
  console.log('Success', res);
})

2. 프라미스 패턴 (Promise Pattern)

var callBack = function(text){
  return new Promise(function(resolve, reject) {
    console.log('callBackkFunc', text);
    resolve(text + ' done');
  })
}

callBack('test Text').then(function(res){
  console.log('Success', res);
}).catch(function(error){
  console.log('error', error);
})

참조: https://geundung.dev/53

profile
pptrollDev@gmail.com

0개의 댓글