// race的原理 Promise.race = function(values){ return new Promise((resolve,reject)=>{ for(let i = 0 ; i< values.length;i++){ let current = values[i]; if((typeof current === 'object' && current !==null)|| typeof current == 'function'){ let then = current.then; if(typeof then == 'function'){ // 比较哪个promise比较快,谁快用快 then.call(current,resolve,reject) }else{ resolve(current); } }else{ resolve(current); } } }); }