es6 promise对象

function next(){
     return new Promise( function( resolve, reject ){
         var num =7 // Math.floor( Math.random() * 10 );
         if ( num <= 5 ) {
             resolve( num );
         }else {
             reject( new Error("错了") );
         }
    } );
 }
 next( 1 ).then( function( res ){
     console.log( res );
 }).catch( function( res ){
     console.log( res );
 } );

 

posted @ 2018-03-19 14:39  风吹麦浪打  阅读(84)  评论(0编辑  收藏  举报