1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 18:32:22 +00:00

docs(Object):Object.values()

This commit is contained in:
ruanyf 2016-03-10 14:25:46 +08:00
parent 1ae51bdea5
commit afd15697ed
2 changed files with 6 additions and 4 deletions

View File

@ -701,18 +701,19 @@ Object.keys(obj)
目前ES7有一个[提案](https://github.com/tc39/proposal-object-values-entries),引入了跟`Object.keys`配套的`Object.values``Object.entries`
```javascript
let {keys, values, entries} = Object;
let obj = { a: 1, b: 2, c: 3 };
for (let key of keys(obj)) {
// ['a', 'b', 'c']
console.log(key); // 'a', 'b', 'c'
}
for (let value of values(obj)) {
// [1, 2, 3]
console.log(value); // 1, 2, 3
}
for (let [key, value] of entries(obj)) {
// [['a', 1], ['b', 2], ['c', 3]]
console.log([key, value]); // ['a', 1], ['b', 2], ['c', 3]
}
```
@ -739,7 +740,7 @@ Object.values(obj)
`Object.values`只返回对象自身的可遍历属性。
```javascript
var obj = Object.create({}, {p: 42});
var obj = Object.create({}, {p: {value: 42}});
Object.values(obj) // []
```

View File

@ -35,6 +35,7 @@
- kangax, [Why typeof is no longer “safe”](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15): 讨论在块级作用域内let命令的变量声明和赋值的行为
- Axel Rauschmayer, [Variables and scoping in ECMAScript 6](http://www.2ality.com/2015/02/es6-scoping.html): 讨论块级作用域与let和const的行为
- Nicolas Bevacqua, [ES6 Let, Const and the “Temporal Dead Zone” (TDZ) in Depth](http://ponyfoo.com/articles/es6-let-const-and-temporal-dead-zone-in-depth)
- acorn, [Function statements in strict mode](https://github.com/ternjs/acorn/issues/118): 块级作用域对严格模式的函数声明的影响
## 解构赋值