* Replace tiny bitmaps with base64-encoded URIs
* Optimize SVGs; replace logo PNG with SVG
* Modernize favicon
* Embed CSS; a bit unorthodox, but we’re a single page so there’s no point in separate .css files and their separate HTTP requests
* Documentation is now markdown, converted to HTML on compilation
* Render the examples when we’re rendering index.html; they compile so quickly that there’s no need to pre-render them and save the intermediate .js files
* Split apart index.html into components that Cakefile assembles, so that we can add in logic to include different files for v1 versus v2
* Split building index.html and building test.html into two tasks; collapse the parts of `releaseHeader` into one compact function
* Move include logic into templates
* Get error messages tests to work in the browser
* Update output index.html
* Split body into nav and body
* Watch subtemplates
* Revert "Split body into nav and body"
This reverts commit ec9e559ec0.
* Add marked
* Update gitignore
* Use idiomatic markdown output for code blocks (<pre><code>)
* Handle ids within the template, not in the Cakefile; remove marked’s auto-generated and conflicting ids
* Move the `codeFor` function into versioned folders, so that v1 and v2 docs can have different example code blocks/editors
* Update packages, including new highlight.js which supports our newer keywords and triple backticks (docs output is unchanged)
1.5 KiB
Destructuring Assignment
Just like JavaScript (since ES2015), CoffeeScript has destructuring assignment syntax. 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. In the simplest case, it can be used for parallel assignment:
codeFor('parallel_assignment', 'theBait')
But it’s also helpful for dealing with functions that return multiple values.
codeFor('multiple_return_values', 'forecast')
Destructuring assignment can be used with any depth of array and object nesting, to help pull out deeply nested properties.
codeFor('object_extraction', 'name + "-" + street')
Destructuring assignment can even be combined with splats.
codeFor('patterns_and_splats', 'contents.join("")')
Expansion can be used to retrieve elements from the end of an array without having to assign the rest of its values. It works in function parameter lists as well.
codeFor('expansion', 'first + " " + last')
Destructuring assignment is also useful when combined with class constructors to assign properties to your instance from an options object passed to the constructor.
codeFor('constructor_destructuring', 'tim.age + " " + tim.height')
The above example also demonstrates that if properties are missing in the destructured object or array, you can, just like in JavaScript, provide defaults. The difference with JavaScript is that CoffeeScript, as always, treats both null and undefined the same.