paulmillr / es6-shim

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

For statement doesn't loop? #458

Closed Xotic750 closed 5 years ago

Xotic750 commented 5 years ago

https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1055

Is this a mistake? Surely just an if?

cscott commented 5 years ago

Yes, looks to be a think-o dating from f77f9f52ccc4765a0674a001fd1f258fdd7cf58a. The current spec is https://www.ecma-international.org/ecma-262/6.0/#sec-%arrayiteratorprototype%.next and doesn't have a for loop. (I think the for loop was from some intermediate stage where we were expecting to skip entries in sparse arrays.)

ljharb commented 5 years ago

Of course it loops - it just doesn't have an initializer, because var i = this.i is already done higher up in the function.

There certainly may be a better way to express it, but there's nothing broken about it.

Xotic750 commented 5 years ago

Ok, I don't think that I'd describe it as a loop as it returns unconditionally, I wasn't suggesting that it was broken more a strange use of for.

ljharb commented 5 years ago

Going to close this; but if there's a compelling reason to refactor that code (including "is much clearer to read") then a PR would be welcome!