es6: add exponent operator
This commit is contained in:
parent
60eb88c055
commit
1f91de36b3
20
es6.md
20
es6.md
|
@ -108,6 +108,7 @@ class Circle extends Shape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
{: data-line="1,3,8,13,18"}
|
||||||
|
|
||||||
Syntactic sugar for prototypes.
|
Syntactic sugar for prototypes.
|
||||||
See: [Classes](http://babeljs.io/docs/learn-es2015/#classes)
|
See: [Classes](http://babeljs.io/docs/learn-es2015/#classes)
|
||||||
|
@ -126,6 +127,7 @@ for (let {title, artist} in songs) {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Functions
|
// Functions
|
||||||
|
@ -135,10 +137,19 @@ function greet({ name, greeting }) {
|
||||||
|
|
||||||
greet({ name: 'Larry', greeting: 'Ahoy' })
|
greet({ name: 'Larry', greeting: 'Ahoy' })
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
Supports for matching arrays and objects.
|
Supports for matching arrays and objects.
|
||||||
See: [Destructuring](http://babeljs.io/docs/learn-es2015/#destructuring)
|
See: [Destructuring](http://babeljs.io/docs/learn-es2015/#destructuring)
|
||||||
|
|
||||||
|
### Exponent operator
|
||||||
|
|
||||||
|
```js
|
||||||
|
const byte = 2 ** 8
|
||||||
|
// Same as: Math.pow(2, 8)
|
||||||
|
```
|
||||||
|
{: data-line="1"}
|
||||||
|
|
||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
@ -150,6 +161,7 @@ function greet (name = "Jerry") {
|
||||||
return `Hello ${name}`
|
return `Hello ${name}`
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Rest arguments
|
// Rest arguments
|
||||||
|
@ -158,11 +170,14 @@ function fn(x, ...y) {
|
||||||
return x * y.length
|
return x * y.length
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Spread
|
// Spread
|
||||||
fn(...[1, 2, 3]) // same as fn(1, 2, 3)
|
fn(...[1, 2, 3])
|
||||||
|
// same as fn(1, 2, 3)
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
Default, rest, spread.
|
Default, rest, spread.
|
||||||
See: [Function arguments](http://babeljs.io/docs/learn-es2015/#default-rest-spread)
|
See: [Function arguments](http://babeljs.io/docs/learn-es2015/#default-rest-spread)
|
||||||
|
@ -175,6 +190,7 @@ setTimeout(() => {
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// With arguments
|
// With arguments
|
||||||
|
@ -182,12 +198,14 @@ readFile('text.txt', (err, data) => {
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Short syntax (no `return` without `{}`)
|
// Short syntax (no `return` without `{}`)
|
||||||
numbers.map(n => n * 2)
|
numbers.map(n => n * 2)
|
||||||
// Same as: numbers.map(function (n) { return n * 2 })
|
// Same as: numbers.map(function (n) { return n * 2 })
|
||||||
```
|
```
|
||||||
|
{: data-line="2"}
|
||||||
|
|
||||||
Like functions but with `this` preserved.
|
Like functions but with `this` preserved.
|
||||||
See: [Fat arrows](http://babeljs.io/docs/learn-es2015/#arrows)
|
See: [Fat arrows](http://babeljs.io/docs/learn-es2015/#arrows)
|
||||||
|
|
Loading…
Reference in New Issue