aset does not chain in clojurescript
-
12-06-2021 - |
Вопрос
I found a result in clojurescript whon aset is chained:
(def data (js-obj))
(-> data
(aset "a" "a")
(aset "b" "b"))
(aget data "a") ;=> "a"
(aget data "b") ;=> 'returns nothing'
whereas
(-> 1 inc dec) ;=> returns 1, which is fine
Решение
Ankur is right about why this happens; to "work around" it, you should use the more semantically-descriptive:
(doto data
(aset "a" "a")
(aset "b" "b"))
Другие советы
aset
returns the inserted element and not the array object itself, hence in the case of "b" the data
is not threaded to it from previous "a" call.
Не связан с StackOverflow