Update
This commit is contained in:
parent
2c318a2678
commit
8ae383e42a
|
@ -17,6 +17,8 @@
|
|||
`table` supports these:
|
||||
|
||||
{: .-shortcuts}
|
||||
{: .-left-align}
|
||||
{: .-headers}
|
||||
|
||||
`pre` supports these:
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
& th {
|
||||
padding: 8px 16px;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
& tr th:last-child,
|
||||
& tr td:last-child {
|
||||
text-align: right;
|
||||
}
|
||||
|
@ -50,6 +52,11 @@
|
|||
& thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
& thead th {
|
||||
font-weight: normal;
|
||||
color: $base-a;
|
||||
}
|
||||
}
|
||||
|
||||
.MarkdownBody table.-shortcuts {
|
||||
|
@ -65,3 +72,18 @@
|
|||
color: $base-text;
|
||||
}
|
||||
}
|
||||
|
||||
.MarkdownBody table.-left-align {
|
||||
& tr th,
|
||||
& tr td,
|
||||
& tr td:last-child {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
.MarkdownBody table.-headers {
|
||||
& thead {
|
||||
display: table-header-group;
|
||||
border-bottom: solid 1px $dark-line-color;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
---
|
||||
title: JavaScript lazy shortcuts
|
||||
category: JavaScript
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
| What | Lazy mode | "The right way" |
|
||||
| --- | --- | --- |
|
||||
| String to number | `+str` | `parseInt(str, 10)` or `parseFloat()` |
|
||||
| Math floor | `num | 0` | `Math.floor(num)` |
|
||||
| Number to string | `'' + num` | `num.toString()` |
|
||||
| Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
|
||||
| Any to boolean | `!!value` | `Boolean(value)` |
|
||||
| Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
|
||||
## Shortcuts
|
||||
{: .-left-reference}
|
||||
|
||||
> `.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill
|
||||
|
||||
## Examples
|
||||
### Examples
|
||||
|
||||
```js
|
||||
n = +'4096' // n === 4096
|
||||
s = '' + 200 // s === '200'
|
||||
```
|
||||
|
||||
```js
|
||||
now = +new Date()
|
||||
isPublished = !!post.publishedAt
|
||||
```
|
||||
|
||||
### Shortcuts
|
||||
|
||||
| What | Lazy mode | "The right way" |
|
||||
| --- | --- | --- |
|
||||
| String to number | `+str` | `parseInt(str, 10)` _or_ `parseFloat()` |
|
||||
| Math floor | `num | 0` | `Math.floor(num)` |
|
||||
| Number to string | `'' + num` | `num.toString()` |
|
||||
| Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
|
||||
| Any to boolean | `!!value` | `Boolean(value)` |
|
||||
| Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
|
||||
{: .-left-align.-headers}
|
||||
|
||||
`.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill.
|
Loading…
Reference in New Issue