paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

Does the array `of` shim apply to `for...of`? #463

Closed johnaweiss closed 4 years ago

johnaweiss commented 4 years ago

for example

for(var c of "tree 木") { console.log(c); }

Thanks

ljharb commented 4 years ago

In any environment where for..of respects a native Symbol.iterator (or similar), this shim will cover it.

There may be an environment or three where for..of only works on, for example, Maps and Sets, and there's no native Symbols - but it's impossible to do anything about those.

Do you have specific environments in mind?

johnaweiss commented 4 years ago

In any environment where for..of respects a native Symbol.iterator (or similar), this shim will cover it.

Would that include the example code in my question?

Do you have specific environments in mind?

just general cross-browser web-development.

ljharb commented 4 years ago

Yes, that would include that code.

I'm pretty confident you'll be fine; please file an issue with specific details if you find a browser where it doesn't work. (of course, you should be using babel to transpile, which will handle for..of syntax properly)