ES6: add object literal enhancements
This commit is contained in:
parent
bb2bf8f0a0
commit
91738c082d
35
es6.md
35
es6.md
|
@ -48,13 +48,9 @@ world
|
|||
`;
|
||||
```
|
||||
|
||||
### Syntax improvements
|
||||
### Other improvements
|
||||
|
||||
```js
|
||||
// Short object syntax
|
||||
// aka: `exports = { hello:hello, bye:bye }`
|
||||
module.exports = { hello, bye };
|
||||
|
||||
// New string methods
|
||||
"hello".repeat(3)
|
||||
"hello".contains("ll")
|
||||
|
@ -65,6 +61,35 @@ var bin = 0b1010010;
|
|||
var oct = 0755;
|
||||
```
|
||||
|
||||
### Object literal enhancements
|
||||
|
||||
```js
|
||||
// Short object syntax
|
||||
// aka: `exports = { hello:hello, bye:bye }`
|
||||
module.exports = { hello, bye };
|
||||
|
||||
App = {
|
||||
// shorthand for `handler: handler`
|
||||
handler,
|
||||
|
||||
// methods
|
||||
start() {
|
||||
this.go();
|
||||
},
|
||||
|
||||
// getter/setter
|
||||
get closed() {
|
||||
return this.status === 'closed';
|
||||
},
|
||||
|
||||
// custom prototypes
|
||||
__proto__: protoObj,
|
||||
|
||||
// computed property names
|
||||
[ "prop_"+n ]: 42
|
||||
};
|
||||
```
|
||||
|
||||
## Stable ([Babel])
|
||||
|
||||
Available via [Babel]
|
||||
|
|
Loading…
Reference in New Issue