for of loop querySelectorAll

前端 未结 9 828
忘了有多久
忘了有多久 2020-12-11 02:29

Mozilla states that \"for of loops will loop over NodeList objects correctly\". (source: https://developer.mozilla.org/en-US/docs/Web/API/NodeList) However, this doesn\'t wo

9条回答
  •  旧巷少年郎
    2020-12-11 03:02

    The docs are correct, but I wouldn't call this a bug. Rather it's a "not yet implemented feature".

    There is no standard for this, and there is still active discussion on how the DOM should integrate with ES6. Notice that it is clear that querySelectorAll should return something iterable which can be used in a for of loop (as the common expectation demands), but it's not clear how that should happen (Let NodeList implement the Iterable interface? Let some Elements collection subclass Array?).

提交回复
热议问题