关于ES4"的"生成和迭代the docs后,我添加了以下polyfill:
(Symbol as any).asyncIterator = Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator");
这会导致我的浏览器抛出错误:
Uncaught TypeError: Cannot assign to read only property ‘asyncIterator’ of function ‘function Symbol() { [native code] }’
答案 0 :(得分:2)
由于该属性是只读的,因此只有在它不存在时才分配:
if (typeof (Symbol as any).asyncIterator === 'undefined') {
(Symbol as any).asyncIterator = Symbol.asyncIterator || Symbol('asyncIterator');
}