💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# generator yield既可以传参,也可以返回 ## 1.1传参 ~~~ function *show(){ alert("a"); let a = yield; alert("b"); alert(a); } let gen = show(); gen.next(); gen.next(5); ~~~ 复制 ## 1.2返回值 ~~~ function *show(){ alert("a"); yield 12; alert("b"); } let gen = show(); let obj1 = gen.next(); let obj2 = gen.next(); console.log(obj1); //{value: 12, done: false} console.log(obj2); //{value: undefined, done: true} ~~~ ~~~ //最后一个值靠return function *show(){ alert("a"); yield 12; alert("b"); return 22; } let gen = show(); let obj1 = gen.next(); let obj2 = gen.next(); console.log(obj1); //{value: 12, done: false} console.log(obj2); //{value: 22, done: true} ~~~