Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning ClojureScript

You're reading from   Learning ClojureScript Master the art of agile single page web application development with ClojureScript

Arrow left icon
Product type Paperback
Published in Jun 2016
Publisher
ISBN-13 9781785887635
Length 320 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Allen Rohner Allen Rohner
Author Profile Icon Allen Rohner
Allen Rohner
W. David Jarvis W. David Jarvis
Author Profile Icon W. David Jarvis
W. David Jarvis
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Getting Ready for ClojureScript Development FREE CHAPTER 2. ClojureScript Language Fundamentals 3. Advanced ClojureScript Concepts 4. Web Applications Basics with ClojureScript 5. Building Single Page Applications 6. Building Richer Web Applications 7. Going Further with ClojureScript 8. Bundling ClojureScript for Production

Advanced destructuring and namespaces

In this section, we'll dig further into ClojureScript's destructuring syntax. We'll also learn about ClojureScript namespaces. If you're familiar with JavaScript ES6 modules, namespaces are sort of akin to that-they're essentially modules within which variable and function definitions are located and a collection of imported libraries can be defined, often with local bindings for convenience.

Destructuring

Destructuring in ClojureScript provides a way of binding values to local variables. We've already seen a few simple examples of how this works with the code in previous sections, but destructuring in ClojureScript is extremely powerful and so comprehensive that it's worth looking at some more advanced patterns of it.

First, let's try destructuring the vector [1 2]:

cljs.user=> (let [[a b] [1 2]] (+ a b))
;; => 3

The same destructuring logic works in a nested fashion:

cljs.user=> (let [[[a b] c] [[1 2] 3...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image