for of loop querySelectorAll

前端 未结 9 822
忘了有多久
忘了有多久 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 02:43

    Native Symbol.iterator support for NodeList was added to the WHATWG's DOM spec in 2014.

    Unfortunately, Chrome 51 is the first version of Chrome to support it, and its Beta has only just been released at the time of writing this answer. Also, there's no support in any version of Internet Explorer or Edge.

    To add Symbol.iterator support for NodeList in all browsers to your code, just use the following polyfill :

    NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
    

提交回复
热议问题