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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
---
title: Object.prototype.propertyIsEnumerable()
slug: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable
tags:
- JavaScript
- Об'єкт
- метод
translation_of: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable
---
<div>{{JSRef}}</div>
<p>Метод <code><strong>propertyIsEnumerable()</strong></code> повертає булеве значення, що позначає, чи є вказана властивість перелічуваною.</p>
<div>{{EmbedInteractiveExample("pages/js/object-prototype-propertyisenumerable.html")}}</div>
<h2 id="Синтаксис">Синтаксис</h2>
<pre class="syntaxbox"><code><var>obj</var>.propertyIsEnumerable(<var>prop</var>)</code></pre>
<h3 id="Параметри">Параметри</h3>
<dl>
<dt><code>prop</code></dt>
<dd>Ім'я властивості, яку необхідно перевірити.</dd>
</dl>
<h3 id="Значення_що_повертається">Значення, що повертається</h3>
<p>{{jsxref("Boolean","Булеве значення")}}, що позначає, чи є вказана властивість перелічуваною.</p>
<h2 id="Опис">Опис</h2>
<p>Кожен об'єкт має метод <code>propertyIsEnumerable</code>. Цей метод може визначити, чи може вказана властивість об'єкта бути перелічена циклом {{jsxref("Statements/for...in", "for...in")}}, за винятком властивостей, успадкованих через ланцюжок прототипів. Якщо об'єкт не має вказаної властивості, метод поверне <code>false</code>.</p>
<h2 id="Приклади">Приклади</h2>
<h3 id="Базове_використання_propertyIsEnumerable">Базове використання <code>propertyIsEnumerable</code></h3>
<p>Наступний приклад демонструє використання <code>propertyIsEnumerable</code> на об'єктах та масивах:</p>
<pre class="brush: js">var o = {};
var a = [];
o.prop = 'перелічувана';
a[0] = 'перелічувана';
o.propertyIsEnumerable('prop'); // повертає true
a.propertyIsEnumerable(0); // повертає true
</pre>
<h3 id="Визначені_користувачем_обєкти_проти_вбудованих_обєктів">Визначені користувачем об'єкти проти вбудованих об'єктів</h3>
<p>Наступний приклад демонструє перелічуваність визначених користувачем властивостей у порівнянні з вбудованими:</p>
<pre class="brush: js">var a = ['перелічувана'];
a.propertyIsEnumerable(0); // повертає true
a.propertyIsEnumerable('length'); // повертає false
Math.propertyIsEnumerable('random'); // повертає false
this.propertyIsEnumerable('Math'); // повертає false
</pre>
<h3 id="Прямі_властивості_проти_успадкованих">Прямі властивості проти успадкованих</h3>
<pre class="brush: js">var a = [];
a.propertyIsEnumerable('constructor'); // повертає false
function firstConstructor() {
this.property = 'не перелічувана';
}
firstConstructor.prototype.firstMethod = function() {};
function secondConstructor() {
this.method = function method() { return 'перелічувана'; };
}
secondConstructor.prototype = new firstConstructor;
secondConstructor.prototype.constructor = secondConstructor;
var o = new secondConstructor();
o.arbitraryProperty = 'перелічувана';
o.propertyIsEnumerable('arbitraryProperty'); // повертає true
o.propertyIsEnumerable('method'); // повертає true
o.propertyIsEnumerable('property'); // повертає false
o.property = 'перелічувана';
o.propertyIsEnumerable('property'); // повертає true
// Наступні повертають false, оскільки вони присутні на прототипі, який
// propertyIsEnumerable не враховує (хоча останні дві
// перебираються циклом for-in)
o.propertyIsEnumerable('prototype'); // повертає false (згідно з JS 1.8.1/FF3.6)
o.propertyIsEnumerable('constructor'); // повертає false
o.propertyIsEnumerable('firstMethod'); // повертає false
</pre>
<h2 id="Специфікації">Специфікації</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Специфікація</th>
<th scope="col">Статус</th>
<th scope="col">Коментар</th>
</tr>
<tr>
<td>{{SpecName('ES3')}}</td>
<td>{{Spec2('ES3')}}</td>
<td>Початкове визначення</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.2.4.7', 'Object.prototype.propertyIsEnumerable')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-object.prototype.propertyisenumerable', 'Object.prototype.propertyIsEnumerable')}}</td>
<td>{{Spec2('ES6')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-object.prototype.propertyisenumerable', 'Object.prototype.propertyIsEnumerable')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Сумісність_з_веб-переглядачами">Сумісність з веб-переглядачами</h2>
<div>
<p>{{Compat("javascript.builtins.Object.propertyIsEnumerable")}}</p>
</div>
<h2 id="Див._також">Див. також</h2>
<ul>
<li><a href="/uk/docs/Web/JavaScript/Перелічуваність_та_належність_властивостей">Перелічуваність та належність властивостей</a></li>
<li>{{jsxref("Statements/for...in", "for...in")}}</li>
<li>{{jsxref("Object.keys()")}}</li>
<li>{{jsxref("Object.defineProperty()")}}</li>
</ul>
|