Skip to content

Instantly share code, notes, and snippets.

@justjake
Created August 23, 2015 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justjake/0aaf202f67a7e102b0c5 to your computer and use it in GitHub Desktop.
Save justjake/0aaf202f67a7e102b0c5 to your computer and use it in GitHub Desktop.
output of exeriment for compiling mardown to other markdown
> airbnb-style@2.0.0 script /home/justjake/src/javascript
> babel-node ./script/index.js
INPUT MARKDOWN TEXT:
# Destructuring
## Use object destructuring when accessing and using multiple properties of an object.
> Why? Destructuring saves you from creating temporary references for those
> properties.
```javascript
// bad
function getFullName(user) {
const firstName = user.firstName;
const lastName = user.lastName;
return `${firstName} ${lastName}`;
}
// good
function getFullName(obj) {
const { firstName, lastName } = obj;
return `${firstName} ${lastName}`;
}
// best
function getFullName({ firstName, lastName }) {
return `${firstName} ${lastName}`;
}
```
## Use array destructuring.
```javascript
const arr = [1, 2, 3, 4];
// bad
const first = arr[0];
const second = arr[1];
// good
const [first, second] = arr;
```
## Use object destructuring for multiple return values, not array destructuring.
> Why? You can add new properties over time or change the order of things
> without breaking call sites.
```javascript
// bad
function processInput(input) {
// then a miracle occurs
return [left, right, top, bottom];
}
// the caller needs to think about the order of return data
const [left, __, top] = processInput(input);
// good
function processInput(input) {
// then a miracle occurs
return { left, right, top, bottom };
}
// the caller selects only the data they need
const { left, right } = processInput(input);
```
ORIGINAL:
root[9]
├─ heading[1]
│ └─ text: 'Destructuring'
├─ heading[1]
│ └─ text: 'Use object destructuring when accessing and using multiple properties of an object.'
├─ blockquote[1]
│ └─ paragraph[1]
│ └─ text: 'Why? Destructuring saves you from creating temporary references for those
properties.'
├─ code: '(elided)'
├─ heading[1]
│ └─ text: 'Use array destructuring.'
├─ code: '(elided)'
├─ heading[1]
│ └─ text: 'Use object destructuring for multiple return values, not array destructuring.'
├─ blockquote[1]
│ └─ paragraph[1]
│ └─ text: 'Why? You can add new properties over time or change the order of things
without breaking call sites.'
└─ code: '(elided)'
GROUPED:
root[1]
└─ ext.OutlineSection[3]
├─ ext.OutlineSection[2]
│ ├─ blockquote[1]
│ │ └─ paragraph[1]
│ │ └─ text: 'Why? Destructuring saves you from creating temporary references for those
properties.'
│ └─ code: '(elided)'
├─ ext.OutlineSection[1]
│ └─ code: '(elided)'
└─ ext.OutlineSection[2]
├─ blockquote[1]
│ └─ paragraph[1]
│ └─ text: 'Why? You can add new properties over time or change the order of things
without breaking call sites.'
└─ code: '(elided)'
STYLING:
root[1]
└─ ext.Styleguide[1]
└─ ext.Section: 'Destructuring'
BACK BABY:
root[3]
├─ heading[1]
│ └─ text: 'Destructuring'
├─ list[3]
│ ├─ listItem[3]
│ │ ├─ paragraph[6]
│ │ │ ├─ link[1]
│ │ │ │ └─ text: '1.1'
│ │ │ ├─ text: ' '
│ │ │ ├─ html: '<a name="1.1">'
│ │ │ ├─ html: '</a>'
│ │ │ ├─ text: ' '
│ │ │ └─ text: 'Use object destructuring when accessing and using multiple properties of an object.'
│ │ ├─ blockquote[1]
│ │ │ └─ paragraph[1]
│ │ │ └─ text: 'Why? Destructuring saves you from creating temporary references for those
properties.'
│ │ └─ code: '(elided)'
│ ├─ listItem[2]
│ │ ├─ paragraph[6]
│ │ │ ├─ link[1]
│ │ │ │ └─ text: '1.2'
│ │ │ ├─ text: ' '
│ │ │ ├─ html: '<a name="1.2">'
│ │ │ ├─ html: '</a>'
│ │ │ ├─ text: ' '
│ │ │ └─ text: 'Use array destructuring.'
│ │ └─ code: '(elided)'
│ └─ listItem[3]
│ ├─ paragraph[6]
│ │ ├─ link[1]
│ │ │ └─ text: '1.3'
│ │ ├─ text: ' '
│ │ ├─ html: '<a name="1.3">'
│ │ ├─ html: '</a>'
│ │ ├─ text: ' '
│ │ └─ text: 'Use object destructuring for multiple return values, not array destructuring.'
│ ├─ blockquote[1]
│ │ └─ paragraph[1]
│ │ └─ text: 'Why? You can add new properties over time or change the order of things
without breaking call sites.'
│ └─ code: '(elided)'
└─ link[1]
└─ text: '⬆ back to top'
AND VIOLA:
## Destructuring
- [1.1](#1.1) <a name="1.1"></a> Use object destructuring when accessing and using multiple properties of an object.
> Why? Destructuring saves you from creating temporary references for those
> properties.
```javascript
(elided)
```
- [1.2](#1.2) <a name="1.2"></a> Use array destructuring.
```javascript
(elided)
```
- [1.3](#1.3) <a name="1.3"></a> Use object destructuring for multiple return values, not array destructuring.
> Why? You can add new properties over time or change the order of things
> without breaking call sites.
```javascript
(elided)
```
[⬆ back to top](#table-of-contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment