欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

generater 初理解

程序员文章站 2022-07-05 23:23:31
...
function* comparePrice(){
    while(true){
        yield Math.random()*100
    }
}
var limitPrice = 50
var price = 100
while(price > limitPrice){
	console.log(`this is price ${price}`)
    price = comparePrice().next().value
}
console.log(`this is lastPrice ${price}`)
// this is price 62.20384758361717
// this is lastPrice 32.9677543460043
相关标签: js javascript