Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove
forEach
from majority of DOM collection prototypes
These appear to be added to address #329. However, only NodeList and DOMTokenList are documented and tested to have forEach on their prototypes.
- Loading branch information
c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a break change for accidently using forEach on FileList.
c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I was sure that some mistakenly used it. But it's not a standard, it was not documented and it was added because of a bug - so it's a bugfix and it was required to add it to prevent more cases of this.
c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zloirock,
And based on this list in
internals/dom-iterables.js
:This means that we add the
forEach
prototype on all the DOM iterables that already support forEach like the NodeList (https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach), but we don't add support for the ones that don't support it.Correct me if I'm wrong but shouldn't we do the opposite?
if (!DOMIterables[COLLECTION_NAME]) {
After updating to the latest core-js, printing in the console
HTMLCollection.prototype
does not show theforEach
function (and it did in the previous version) whereasNodeList.prototype
does.We can still convert it to an array to benefit from the built-in forEach but if this change is intended, it is a breaking change to not be able to do
document.getElementsByClassName('my-class').forEach
anymore, like we could before this release. And in this case it should be a major release.Let me know! :)
c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antoniandre it should be added only to
NodeList
andDOMTokenList
, other DOM collections do not contain it by the spec and adding something non-standard is not something good.c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand.
Then it should be documented as a lot of people may get the same problem as me where it was supported before and breaking after update. ;)
c01268a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's documented that it's added only to
NodeList
andDOMTokenList
, the docs never said something different, this bugfix is documented in the changelog.