Tutorial by Examples

When you assign an array or object literal to a value, CoffeeScript breaks up and matches both sides against each other, assigning the values on the right to the variables on the left. # Swap [x, y] = [y, x]
person = name: "Duder von Broheim" age: 27 address: "123 Fake St" phoneNumber: "867-5309" {name, age, address, phoneNumber} = person
CoffeeScript allows to deconstruct objects and arrays when they are fed to functions as arguments. A function that leverages deconstruction will specify in its signature all the fields that are expected within its body. When invoking such function, an object or array containing all the expected fie...
array = [1, 2, 3, 4] [first] = array # 1 [..., last] = array # 4 [first, middle..., last] = array # first is 1, middle is [2, 3], last is 4

Page 1 of 1