Why aren't NodeList / HtmlCollection seqable?

一笑奈何 提交于 2019-12-04 08:06:55

问题


As a newcomer to Clojurescript it appears to me that every Clojurescript project will have some snippet of code like this:

(extend-type js/NodeList
  ISeqable
  (-seq [array] (array-seq array 0)))

Why isn't this part of the core library?


回答1:


You have to think that clojurescript is a compiler to javascript as a language, not only browser JavaScript. You can also use it in other platforms like nodejs or with the QT library where NodeList does not exist (because it is part of the Dom api and not the standard language).




回答2:


If you are looking for a way to create a sequence from a NodeList there is array-seq function.

(array-seq (js/document.querySelectorAll "div"))


来源:https://stackoverflow.com/questions/23616019/why-arent-nodelist-htmlcollection-seqable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!