【发布时间】:2020-05-24 14:36:49
【问题描述】:
我正在努力使我的生成器更灵活
来自:
function *formValidationSequence () {
yield someRef.current.func()
yield someOtherRef.current.func()
...
}
至此:
const array = [someRef, someOtherRef]
const handler = (array) => {
const sequence = testSequence(function *() {
yield* array.map(item => item.current.func())
})
}
但它不起作用。我想为数组中的每个 ref/item 动态创建 yield,而不是立即调用它们。
应该怎么做?
【问题讨论】:
-
为什么是
map?为什么不for(const el of array) yield el.current.func()? -
func()在做什么,什么不工作? -
@Jonas Wilms 是的,当然!我没想到。谢谢
标签: javascript generator