-
Notifications
You must be signed in to change notification settings - Fork 22.7k
Content bug: Number.isInteger polyfill slightly incorrect and a bit confusing #8034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Given that all browsers support this feature for years (except IE). Shouldn't we delete the polyfill? |
@teoli2003 That works too. 😃 Although (heaven help us) there are still enterprises reliant on IE11 because of legacy junk. :-| I had to do some maintenance for one of those just earlier this year. (I did tell them they should move off it, or at least use an AD policy to disallow using it for browsing internet sites, restricting it to the intranet apps they still rely on.) |
That's true. I see there is a polyfill link in the |
@teoli2003 It depends entirely on what position MDN has or wants to have with regard to polyfills: Have them, or defer to https://github.com/zloirock/core-js or https://github.com/es-shims or other such. That's probably an editorial-level decision. Having a polyfill on the page does provide educational value, but at the cost of maintenance (this specific one is unlikely to change, but others may over time as the spec changes). |
We are leaning towards linking to external websites. My question was more: Is the linked polyfill good? |
It doesn't follow the letter of the spec, and is extremely hard to find in the code base (it's here), so it has zero educational value. I assume it works and is added correctly (e.g., with the right value for |
Yes, I agree. The original discussion of this was https://discourse.mozilla.org/t/mdn-rfc-001-mdn-wiki-pages-shouldnt-be-a-distributor-of-polyfills/24500 - I think whatever we do decide to do about documenting polyfills on MDN, there's a pretty clear consensus for not maintaining them in content. That's also the starting premise of openwebdocs/project#27 . |
What page(s) did you find the problem on?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
Specific page section or heading?
Polyfill
What is the problem?
enumerable: true
(because it uses assignment to create it); it should beenumerable: false
floor(abs(value)) === value
, but the polyfill only doesMath.floor(value) === value
(leaving out theabs
operation). One could naively jump to the conclusion it wouldn't work correctly for negative numbers (I did, oops 😃), but it does seem to work, probably because it doesn't really matter whether youfloor
orceil
(ortrunc
) the value, all we really need to know is that doing that does or doesn't lose some fractional portion. Still, I assume the algorithm is written the way it is for a reason, it's probably best if the polyfill implements it faithfully.isInteger
(which is spec'd).What did you expect to see?
Something like this:
Or alternatively, that without the
Math.abs
operation and an explanation why it's not needed although it's specified.Happy to do a PR with the version above.
Did you test this? If so, how?
Yes, by:
(1) and (3) are incorrect for the current polyfill, correct for the one above.
The text was updated successfully, but these errors were encountered: