forEach method of Node.childNodes?

前端 未结 2 771
时光取名叫无心
时光取名叫无心 2020-11-28 14:31

After providing an incorrect answer concerning the .item() property of Node.childNodes for a question, I inspected __proto__ of the returned

2条回答
  •  旧时难觅i
    2020-11-28 14:52

    Is the method available only at relatively recent versions of Chrome / Chromium? If yes, is this documented?

    Yes, this is new in DOM4, so not widely available.

    Is there any documentation concerning the forEach() method of Node.childNodes?

    See Add support for [ArrayClass] and use that on NodeList on the Chromium bug tracker:

    From https://bugs.webkit.org/show_bug.cgi?id=81573

    http://dom.spec.whatwg.org/#interface-nodelist

    DOM4 specs NodeList as having Array.prototype in its prototype chain.

    Some more background for this one. [ArrayClass] allows us to do things like document.querySelectorAll('.foo').forEach etc. The patch at bugs.webkit.org has a runtime flag because it is unclear if this will still be possible to achieve.

    Historically these array-like objects did not include these methods from the array prototype, leading to code like Array.prototype.forEach.call(nodeList, function() { ... }). This is now meant to change in DOM4.

提交回复
热议问题