Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Variable and argument destructuring

This is the last piece that you'll need to understand, as it tends to appear in a lot of JavaScript code tied to Phoenix channels. This last concept is centered around destructuring variables and arguments and it actually works a lot like what you're used to in Elixir. It basically allows you to do things like this:

const person = {  firstName: "Jane",  lastName: "Smith",  age: 30};const { firstName, lastName, age } = person;console.log(firstName); // Will output "Jane"console.log(lastName); // Will output "Smith"console.log(age); // Will output "30"

This is a nice, cleaner way of doing something that previously required as much code as this:

const person = {  firstName: "Jane",  lastName: "Smith",  age: 30
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content