Open heatherleaf opened 10 years ago
I solved it for myself by just copying (and renaming Array to String) the following code from the function polyfillArray
to the function polyfillString
(in file src/runtime/runtime.js
):
defineProperty(Array.prototype, Symbol.iterator, method(function() {
var index = 0;
var array = this;
return {
next: function() {
if (index < array.length) {
return {value: array[index++], done: false};
}
return {value: undefined, done: true};
}
};
}));
This is not compatible with what will be in ES6. See http://mathiasbynens.be/notes/javascript-unicode for more details.
@arv what about array-like objects such as HTMLCollection, NodeList or NamedNodeMap? Can I use heatherleaf's solution with those objects?
@jarek-foksa Most DOM collections will just use ArrayIterator
For-of loops cannot iterate over strings. E.g., the following code prints "item 1" and "item 2" and then aborts with error "TypeError: Object ABCD has no method 'iterator'"