paulmillr / es6-shim

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

Array.prototype.find is always shimmed #433

Closed zerovox closed 7 years ago

zerovox commented 7 years ago
if (![, 1].find(function (item, idx) { return idx === 0; })) {
  overrideNative(Array.prototype, 'find', ArrayPrototypeShims.find);
}

I believe this will shim find if the behaviour of find is correct. [, 1].find(function (item, idx) { return idx === 0; }) should return undefined (assuming my understanding that [, 1] should act the same as [undefined, 1], so we want to shim if it returns 1. This means the negation is placed incorrectly.

ljharb commented 7 years ago

That's not entirely accurate - we want to shim if it reaches the iteration of index 1 - but you're correct that this seems wrong, because of the undefined.

I'll get a fix out for this shortly.

ljharb commented 7 years ago

(note that this isn't breaking anything, it's just needlessly shimming)

ljharb commented 7 years ago

Published as v0.35.3.