yield断点的使用
function* demo(stock){ while(true){ yield Math.random()*10; //获取最近价格 } } var demoa = demo("IBM"); let limitPrice = 1; //想要的价格 let price = 100; //当前价格 while(price > limitPrice){ price = demoa.next().value; console.log(`${price}`); } console.log(`${price}`); //最后想要的价格 // function* demo(){ // console.log(1111); // yield; // console.log(2222); // } // let demoa = demo(); // demoa.next(); // demoa.next();

浙公网安备 33010602011771号