2017-09-08 10 views
1

the docs爲「生成和迭代ES5」跑的時候,我增加了以下填充工具:錯誤打字稿與異步迭代目標ES5並在瀏覽器

(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] }’ 

回答

1

由於屬性是隻讀,只分配它,當它不存在:

if (typeof (Symbol as any).asyncIterator === 'undefined') { 
(Symbol as any).asyncIterator = Symbol.asyncIterator || Symbol('asyncIterator'); 
}