# js/Map and js/Set not handled in js-\>clj?

**URL:** https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698
**Category:** Beginners
**Tags:** clojurescript
**Created:** [April 22, 2024, 11:18am UTC](https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698 "2024-04-22T11:18:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zweifisch](https://clojureverse.org/user_avatar/clojureverse.org/zweifisch/32/5401_2.png) [@zweifisch](https://clojureverse.org/u/zweifisch)
#### Post date: [April 22, 2024, 11:18am UTC](https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698/1 "2024-04-22T11:18:52Z")

</div>

this looks incomplete to me

---

<div class="post-metadata">

### Author: ![p-himik](https://clojureverse.org/user_avatar/clojureverse.org/p-himik/32/4137_2.png) [@p-himik](https://clojureverse.org/u/p-himik)
#### Post date: [April 22, 2024, 11:40am UTC](https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698/2 "2024-04-22T11:40:13Z")

</div>

`js->clj` significantly predates the introduction of `Map` and `Set` to JS. But that by itself, of course, doesn’t explain why it hasn’t been added.

I don’t know whether it’s been considered at all, but I can think of a couple of reasons to avoid adding support for `Map` and `Set` to the built-in `js->clj` function:

- Both `Map` and `Set` preserve insertion order. The CLJS counterparts do not
- Both `Map` and `Set` rely on key comparison algorithm that differs from CLJS, which can lead to loss of data after a conversion

Whether or not those are relevant to the code you write is unknown to CLJS, so it can’t make all the right decisions for everyone.

At the same time, the `js->clj` function is trivial in its implementation - you can easily write the same function and extend it in any way you want, with all the specifics in mind.

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [April 22, 2024, 11:45am UTC](https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698/3 "2024-04-22T11:45:56Z")

</div>

The above is correct.

I’ll add to that that `js->clj` is meant to convert JS objects. It never converts any instances of classes by default. You can use the `IEncodeClojure` protocol to implement support for that, although I would caution against doing so given the above reasons.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [October 21, 2024, 11:46pm UTC](https://clojureverse.org/t/js-map-and-js-set-not-handled-in-js-clj/10698/4 "2024-10-21T23:46:31Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
