记录学习、使用过程中会遇到的一些点

刚开始学 clj/cljs 的时候,常常自我怀疑干嘛要特意学这个

于是得牢记 clj/cljs 的一大优势,可以引用 Browser REPL (bREPL) 的介绍

在代码最开始的时候是一张流程图,经过一次次重构,会慢慢变成一张结构设计图 One of the main reasons to use a LISP dialect like CLJ is its REPL (Read Eval Print Loop), which enables a very interactive style of programming. CLJS communities worked very hard to bring the same REPL-based programming experience to CLJS available in CLJ, and created a way to connect a CLJS REPL to almost any JS engine, including browser-embedded engines. This style of programming allows you to evaluate CLJS forms in the REPL and receive an immediate feedback in the browser to which the REPL is connected.

Clojure

常用

  1. ;; 查看指定函数源码
  2. (source +)

语法

  • do 语句:do returns the value of its last expression.

ClojureScript

常用

  1. ;; 正常调用 browser DOM 的例子
  2. cljs.user=> js/window
  3. cljs.user=> js/document
  4. cljs.user=> js/console
  5. cljs.user=> (js/console.log "Hello from ClojureScript!")
  1. ;; 语法糖 syntactic sugar
  2. cljs.user=> (.log js/console "Hello from ClojureScript!")
  1. ;; 获取 DOM 对象属性 get DOM element property
  2. cljs.user=> (.-property (.getElementById js/document "objId"))
  1. ;; 设置 DOM 对象属性值 set a value for a DOM element
  2. cljs.user=> (set! (.-property (.getElementById js/document "objId"))
  3. cljs.user=> (set! (.-background (.-style (.-body js/document))) "#333")
  1. ;; 获取字符串或 Collection 类型长度 counting the length of a string
  2. cljs.user=> (count (.-property (element)))

cljs 做开发会用到的库

  • domina
  • om/om.next
  • reagent
  • re-frame
  • rum
  • citrus


(shadow.cljs.devtools.api/repl :renderer)
**


Specific Vocabulary

  • IFDE — Immediate Feedback Development Environment