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:
parent
1ae51bdea5
commit
afd15697ed
@ -701,18 +701,19 @@ Object.keys(obj)
|
|||||||
目前,ES7有一个[提案](https://github.com/tc39/proposal-object-values-entries),引入了跟`Object.keys`配套的`Object.values`和`Object.entries`。
|
目前,ES7有一个[提案](https://github.com/tc39/proposal-object-values-entries),引入了跟`Object.keys`配套的`Object.values`和`Object.entries`。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
let {keys, values, entries} = Object;
|
||||||
let obj = { a: 1, b: 2, c: 3 };
|
let obj = { a: 1, b: 2, c: 3 };
|
||||||
|
|
||||||
for (let key of keys(obj)) {
|
for (let key of keys(obj)) {
|
||||||
// ['a', 'b', 'c']
|
console.log(key); // 'a', 'b', 'c'
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let value of values(obj)) {
|
for (let value of values(obj)) {
|
||||||
// [1, 2, 3]
|
console.log(value); // 1, 2, 3
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let [key, value] of entries(obj)) {
|
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`只返回对象自身的可遍历属性。
|
`Object.values`只返回对象自身的可遍历属性。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var obj = Object.create({}, {p: 42});
|
var obj = Object.create({}, {p: {value: 42}});
|
||||||
Object.values(obj) // []
|
Object.values(obj) // []
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
- kangax, [Why typeof is no longer “safe”](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15): 讨论在块级作用域内,let命令的变量声明和赋值的行为
|
- 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的行为
|
- 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)
|
- 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): 块级作用域对严格模式的函数声明的影响
|
||||||
|
|
||||||
## 解构赋值
|
## 解构赋值
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user