题目要求: 将 then 方法添加到您的承诺中。 使用 result 作为其回调函数的参数,并将结果记录到控制台。 解决的代码如下: const makeServerRequest = new Promise (( resolve , reject ) => { // responseFromServer is set to true to represent a successful response from a server let responseFromServer = true ; if ( responseFromServer ) { resolve ( "We got the data" ); } else { reject ( "Data not received" ); } }) makeServerRequest . then ( ( result )=>{ console . log ( result ); } ); 要求增加异常处理,代码如下: makeServerRequest . catch ( ( error )=> { console . log ( error ); } );
Just want to spend this life happier.