aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/reflect/ownkeys/index.html
blob: bfa393f2ffb3551a466590319c7712b85acd61d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: Reflect.ownKeys()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys
tags:
  - Reflect
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys
---
<div>{{JSRef}}</div>

<p>静态方法 <code><strong>Reflect</strong></code><strong><code>.ownKeys()</code></strong> 返回一个由目标对象自身的属性键组成的数组。</p>

<div>{{EmbedInteractiveExample("pages/js/reflect-ownkeys.html")}}</div>



<h2 id="语法">语法</h2>

<pre class="syntaxbox">Reflect.ownKeys(target)
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>target</code></dt>
 <dd>获取自身属性键的目标对象。</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>由目标对象的自身属性键组成的 {{jsxref("Array")}}。 </p>

<h3 id="异常">异常</h3>

<p>如果目标不是 {{jsxref("Object")}},抛出一个 {{jsxref("TypeError")}}</p>

<h2 id="描述">描述</h2>

<p><code>Reflect.ownKeys</code> 方法返回一个由目标对象自身的属性键组成的数组。它的返回值等同于<code>{{jsxref("Object.getOwnPropertyNames")}}(target).concat({{jsxref("Object.getOwnPropertySymbols")}}(target))。</code></p>

<h2 id="示例">示例</h2>

<h3 id="使用_Reflect.ownKeys()">使用 <code>Reflect.ownKeys()</code></h3>

<pre class="brush: js">Reflect.ownKeys({z: 3, y: 2, x: 1}); // [ "z", "y", "x" ]
Reflect.ownKeys([]); // ["length"]

var sym = Symbol.for("comet");
var sym2 = Symbol.for("meteor");
var obj = {[sym]: 0, "str": 0, "773": 0, "0": 0,
           [sym2]: 0, "-1": 0, "8": 0, "second str": 0};
Reflect.ownKeys(obj);
// [ "0", "8", "773", "str", "-1", "second str", Symbol(comet), Symbol(meteor) ]
// Indexes in numeric order,
// strings in insertion order,
// symbols in insertion order
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-reflect.ownkeys', 'Reflect.ownKeys')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-reflect.ownkeys', 'Reflect.ownKeys')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>



<p>{{Compat("javascript.builtins.Reflect.ownKeys")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{jsxref("Reflect")}}</li>
 <li>{{jsxref("Object.getOwnPropertyNames()")}}</li>
</ul>