Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top