Skip to content

Instantly share code, notes, and snippets.

@mason-stewart
Created May 13, 2012 18:17
Show Gist options
  • Select an option

  • Save mason-stewart/2689596 to your computer and use it in GitHub Desktop.

Select an option

Save mason-stewart/2689596 to your computer and use it in GitHub Desktop.
cljs question
(ns masondesu.main)
(def x "foo")
(.log js/console x) ;; logs "foo". outputs `console.log(masondesu.main.x)`
(def mason (js-obj name "Mason Stewart" beardPower 5000))
(.log js/console mason.name ) ;; throws error. outputs `console.log(mason.name)`
@mason-stewart

Copy link
Copy Markdown
Author

Why is the namespacing incorrect on the second console.log() ?

@swannodette

Copy link
Copy Markdown

mason.name is not valid ClojureScript property access:

For interop purposes you want this:

(def mason (js-obj "name" "Mason Steward" "beardPower" 5000))
(.log js/console (aget mason "name"))

But if you're writing idiomatic Clojure:

(def mason {:name" "Mason Steward" :beard-power" 5000})
(.log js/console (:name mason))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment