A living tutorial for ClojureScript.
- Java 1.6+
- Maven 2
- Leiningen
- Text editor
To build the included source files, enter and run the following at a command prompt:
lein deps
lein cljsbuild once
To start ClojureScript 101 locally using Leiningen, type the following command in the project directory:
lein run 8080
Then visit http://localhost:8080/ and hack away.
Common ClojureScript functions and macros work as expected:
(map (fn [n] (* n n n)) [1 2 3 4])
;=> (1 8 27 64)
(for [[k v] {:a 1 :b 2}] [v k])
;=> ([1 :a] [2 :b])
(if (< x 10) :less :more)
;=> :less
(defn sqr [n] (* n n))
(map sqr [1 2 3])
;=> (1 4 9)
(deftype Cons [h t])
(.-t (Cons. 1 108))
;=> 108
(defmulti classify-age :age)
(defmethod classify-age 36 [_] :ancient)
(classify-age {:age 36})
;=> :ancient
To use jQuery from the ClojureScript 101 REPL, try the following:
(def anchor (js/jQuery "a"))
(.text anchor)
;=> "Source..."
(.text anchor "Github repo...")
- ClojureScript 101
- Target audience: those who know about ClojureScript but have never used it
- Prerequisite: Clojure 101
- Getting up and running
- required tools: lein, editor, Java, etc.
lein cljs-build ...
- Why ClojureScript?
- Just enough ClojureScript
- What is different from Clojure?
- Compilation
- Namespaces
- Interop
- Libraries
- Briefly mention macros, more coverage in 102
- Compilation
- High level overview of compilation
- Google Closure Compiler
- Will be covered in more detail in ClojureScript 102
- Namespaces
- From a ClojureScript perspective
- Basic JavaScript interop
- The
js
magic namespace - Interact with JavaScript environment
- The
- Libraries
- Using Google Closure libraries
- Using jQuery
Copyright (C) 2014, Fogus
Distributed under the Eclipse Public License, the same as Clojure.