mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 18:32:22 +00:00
docs(Object): edit Object.values()
This commit is contained in:
parent
186a84dce7
commit
4d599e8785
@ -825,7 +825,17 @@ var obj = Object.create({}, {p: {value: 42}});
|
||||
Object.values(obj) // []
|
||||
```
|
||||
|
||||
上面代码中,`Object.create`方法的第二个参数添加的对象属性(属性`p`),如果不显式声明,默认是不可遍历的,因为`p`是继承的属性,而不是对象自身的属性。`Object.values`不会返回这个属性。
|
||||
上面代码中,`Object.create`方法的第二个参数添加的对象属性(属性`p`),如果不显式声明,默认是不可遍历的,因为`p`的属性描述对象的`enumerable`默认是`false`,`Object.values`不会返回这个属性。只要把`enumerable`改成`true`,`Object.values`就会返回属性`p`的值。
|
||||
|
||||
```javascript
|
||||
var obj = Object.create({}, {p:
|
||||
{
|
||||
value: 42,
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
Object.values(obj) // [42]
|
||||
```
|
||||
|
||||
`Object.values`会过滤属性名为 Symbol 值的属性。
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user