"yield is reserved word" 在 ES6 中

"yield is reserved word" in ES6

我在 react-redux-saga 项目中遇到这个错误:

Syntax error: yield is a reserved word (66:16)

 function* broken(action) { 
  props.forEach(prop => {                                                    
    const res = yield put(blah)   
    // do stuff yada yada in here                                                                           
  })
}

原来内部函数也需要是一个生成器 - 但是 。所以最好使用没有回调的标准循环。类似于:

function* working(action) { 
  for (const prop of props) {
    const res = yield put(blah) 
    // do stuff yada yada in here                                                                           
  }
}