문제

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?

도움이 되었습니까?

해결책

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).

다른 팁

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"))

With a patch for https://clojure.atlassian.net/browse/CLJS-3199 applied in ClojureScript 1.10.741 (seq (js/document.querySelectorAll "div")) now actually works out of the box.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top