[Javascript]コールバックモードvs基本モード


1.コールバックモード

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