NodeList/HTMLCollection #1570

Open
culshaw opened this Issue May 14, 2015 · 5 comments

Comments

Projects
None yet
6 participants
@culshaw

culshaw commented May 14, 2015

Support for NodeList types https://developer.mozilla.org/en/docs/Web/API/NodeList

also very similar (probably the same thing)

https://developer.mozilla.org/en/docs/Web/API/HTMLCollection

@davidflanagan

This comment has been minimized.

Show comment
Hide comment
@davidflanagan

davidflanagan Jan 24, 2017

Now that NodeList.forEach() works in Chrome and Firefox, I'd love to see it on caniuse.com somewhere. MDN has a compatiblity table here: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach

But I'd prefer to be able to find more definitive information at caniuse.com

Now that NodeList.forEach() works in Chrome and Firefox, I'd love to see it on caniuse.com somewhere. MDN has a compatiblity table here: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach

But I'd prefer to be able to find more definitive information at caniuse.com

@thw0rted

This comment has been minimized.

Show comment
Hide comment
@thw0rted

thw0rted Feb 8, 2017

Agreed, I just discovered that NodeList is getting iterator-like methods added but it's still very young -- as of today MDN doesn't have any data at all for MS Edge, for example -- and I tend to rely on caniuse.com as canonical.

thw0rted commented Feb 8, 2017

Agreed, I just discovered that NodeList is getting iterator-like methods added but it's still very young -- as of today MDN doesn't have any data at all for MS Edge, for example -- and I tend to rely on caniuse.com as canonical.

@thw0rted

This comment has been minimized.

Show comment
Hide comment
@thw0rted

thw0rted Jul 12, 2017

FWIW I now use [...document.querySelectorAll(".foo")].forEach and let Babel / polyfill sort it out. I find it more readable and less verbose than most of the alternatives involving Array.prototype.

FWIW I now use [...document.querySelectorAll(".foo")].forEach and let Babel / polyfill sort it out. I find it more readable and less verbose than most of the alternatives involving Array.prototype.

@NiavlysB

This comment has been minimized.

Show comment
Hide comment
@NiavlysB

NiavlysB Feb 19, 2018

@thw0rted I've heard this method is about twice as slow as necessary, and performance aside, I think it's easier and more consistant to use a polyfill:

if (window.NodeList && !NodeList.prototype.forEach) {
    NodeList.prototype.forEach = function (callback, thisArg) {
        thisArg = thisArg || window;
        for (var i = 0; i < this.length; i++) {
            callback.call(thisArg, this[i], i, this);
        }
    };
}

This one is suggested by Mozilla here: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill

@thw0rted I've heard this method is about twice as slow as necessary, and performance aside, I think it's easier and more consistant to use a polyfill:

if (window.NodeList && !NodeList.prototype.forEach) {
    NodeList.prototype.forEach = function (callback, thisArg) {
        thisArg = thisArg || window;
        for (var i = 0; i < this.length; i++) {
            callback.call(thisArg, this[i], i, this);
        }
    };
}

This one is suggested by Mozilla here: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment