You should never extend js/Object. On Thursday, January 12, 2012, Dave Sann <daves...@gmail.com> wrote: > code is below. > Basically - if I extend a protocol on js/Object then I get an error when calling map on a map with integer keys. > Is this a bug or an error on my part? > Cheers > Dave > Results first: > If the extend-protocol and call to 'fred' is commented, ths console shows > "START" > "one" > ([2 1]) > "two" > "three" > ([:2 1]) > "four" > "five" > ([2 1]) > "done" > If the extend-protocol and call to 'fred' is uncommented I get: > > "START" > "one" > ([2 1]) > "two" > "three" > ([:2 1]) > "four" > Uncaught Error: No protocol method ISeqable.-seq defined for type boolean: true > > > > Code: > (ns ptest.main) > > (defn map->js [m] > (let [out (js-obj)] > (doseq [[k v] m] > (aset out (name k) v)) > out)) > > (defn log > ([x] > (let [l (if (map? x) (map->js x) x)] > (.log js/console l) > x)) > ([m x] > (do (log {:msg m :data x}) x))) > (defn log-str > ([x] (do (log (pr-str x)) x)) > ([m x] (do (log-str {:msg m :data x}) x))) > > (log-str "START") > (defprotocol FRED > (fred [this] "fred")) > (log-str "one") > (log-str > (map (fn [[k v]] [k v]) > {2 1})) > (extend-protocol FRED > js/Object > (fred [this] this)) > (log-str "two") > (fred {}) > > (log-str "three") > (log-str > (map (fn [[k v]] [k v]) > {:2 1})) > > (log-str "four") > (def a (doall (map (fn [[k v]] [k v]) > {2 1}))) > > (log-str "five") > (log-str a) > > > (log-str "done") > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en