new Promise(function(resolve,reject){ let i = 3; setTimeout(function(){ if(i>5){ resolve(i); }else{ reject(i); } },2000); }).then(function(index){ console.log(index); },function(index){ console.log(index); }); function demo(callback,callback2){ let i = 3; setTimeout(function(){ if(i>5){ callback(i); }else{ callback2(i); } },1000); } demo(function(index){ console.log(index); },function(index){ console.log(index); });