var now = new Date(); var exitTime = now.getTime() + numberMillis; //numberMillis毫秒超时参数 while (true) { try { //逻辑处理 // 如果符合可以直接return ""; }catch(ignored) { //exception } now = new Date(); if (now.getTime() > exitTime){return ""; } }