forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.jsdoc
More file actions
496 lines (370 loc) · 12.3 KB
/
object.jsdoc
File metadata and controls
496 lines (370 loc) · 12.3 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
Object : undefined
Object is the base in the prototype chain.
JavaScript **Object**s can have any number values stored as properties
(specified by %%/String|**String**%% names or %%/Symbol|**Symbol**%%s).
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2
----
Object() : Object
Same as %%#new_Object_|**new Object()**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.1.1
----
Object(value : Object) : Object
Same as %%#new_Object_Object|**new Object(value)**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.1.1
----
new Object() : Object
Creates an empty object.
Can also be constructed as **{}**.
<example>
// The following are all equivalent
var x = {};
var y = Object();
var z = new Object();
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.2.1
----
new Object(value : Object) : Object
If **value** is a primitive type, creates a box for **value**. Otherwise,
returns **value**.
<example>
var x = true;
console.log(typeof x + ' / ' + typeof Object(x));
console.log(x === Object(x));
var y = {};
console.log(typeof y + ' / ' + typeof Object(y));
console.log(y === Object(y));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.2.1
----
instance[propertyName : String] : Object
Returns the value stored in this at the specified **propertyName**.
This is the same as the **.** style access but also allows the
property name to be specified at runtime using a String of being hardcoded and allows
access to properties that are invalid identifiers (such as including spaces or
starting with a number).
<example>
var x = { foo: 'bar'};
// The following are equivalent
console.log(x.foo);
console.log(x['foo']);
// Use [] indexing when the name is not known ahead of time
var propertyName = 'f' + 'oo';
console.log(x[propertyName]);
</example>
----
instance[symbol : Symbol] : Object
Returns the value stored in this at the specified **symbol**.
<example>
var x = { foo: 'bar'};
</example>
Version:
ECMAScript 2015
----
getPrototypeOf(obj : Object) : Object
Returns the prototype of **obj**.
<example>
console.log(Object.getPrototypeOf([]) === Array.prototype);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.2
----
getOwnPropertyDescriptor(obj : Object, propertyName : String) : PropertyDescriptor
Returns a **PropertyDescriptor** that describes the **propertyName** property on **obj**.
<example>
var x = { foo: 1,
get bar() {
return 'a';
} };
Object.defineProperty(x, 'baz', { value: 2,
writable: true,
enumerable: false,
configurable: true } );
console.dir(Object.getOwnPropertyDescriptor(x, 'foo'));
console.dir(Object.getOwnPropertyDescriptor(x, 'bar'));
console.dir(Object.getOwnPropertyDescriptor(x, 'baz'));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.3
----
getOwnPropertyNames(obj : Object) : Array<String>
Returns an **Array** of the names of all properties set on **obj** including
those that are not enumerable.
See also %%#keys|**keys()**%%.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2,
writable: true,
enumerable: false,
configurable: true } );
console.log(Object.keys(x));
console.log(Object.getOwnPropertyNames(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.4
----
getOwnPropertySymbols(obj : Object) : Array<Symbol>
Returns an **Array** of the symbols of properties set on **obj** including
those that are not enumerable.
<example>
var myObject = { foo: 'bar' };
var mySymbol = Symbol('MySymbol');
myObject[mySymbol] = 'baz';
for (var symbol of Object.getOwnPropertySymbols(myObject)) {
console.log('myObject[' + symbol.toString() + '] = ' + myObject[symbol]);
}
</example>
Version:
ECMAScript 2015
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-object.getownpropertysymbols
----
create(prototype : Object, [propertyDescriptors : Object]) : Object
Returns a new **Object** with prototype equal to **prototype**. Pass
**null** for **prototype** to create an object with no prototype.
Calls
%%#defineProperties|**defineProperties(obj, propertyDescriptors)**%%
with the new object if **propertyDescriptors** is specified.
<example>
var x = Object.create({}, { foo: { value: 1,
writable: true,
enumerable: true,
configurable: true },
bar: { value: 2,
writable: true,
enumerable: false,
configurable: true }});
console.log(x.foo);
console.log(x.bar);
console.log(Object.keys(x));
console.log(Object.getOwnPropertyNames(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.5
----
defineProperty(obj : Object, propertyName : String, propertyDescriptor : PropertyDescriptor) : Object
Defines a new property with name equal to **propertyName** on **obj** with the
supplied descriptor. Returns **obj**.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2,
writable: true,
enumerable: false,
configurable: true } );
console.log(x.foo);
console.log(x.bar);
console.log(Object.keys(x));
console.log(Object.getOwnPropertyNames(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.6
----
defineProperties(obj : Object, propertyDescriptors : Object) : Object
For each property on **propertyDescriptors**, defines a new property on
**obj** with the same name and supplied %%/PropertyDescriptor|**PropertyDescriptor**%%.
Returns **obj**.
<example>
var x = {};
Object.defineProperties(x, { foo: { value: 1,
writable: true,
enumerable: true,
configurable: true },
bar: { value: 2,
writable: true,
enumerable: false,
configurable: true }});
console.log(x.foo);
console.log(x.bar);
console.log(Object.keys(x));
console.log(Object.getOwnPropertyNames(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.7
----
seal(obj : Object) : Object
Same as %%#preventExtensions|**preventExtensions**%% except it also
sets each property as not
%%/PropertyDescriptor#configurable|**configurable**%%. Returns **obj**.
<example>
var x = { foo: 1 };
Object.seal(x);
x.foo = 3;
console.log(x.foo);
x.bar = 1;
console.log(x.bar);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.8
----
freeze(obj : Object) : Object
For each property on **obj**, sets its
%%/PropertyDescriptor#configurable|**PropertyDescriptor.configurable**%%
property to **false** and
%%/PropertyDescriptor#writable|**PropertyDescriptor.writable**%%
property to **false**. Also calls
%%#preventExtensions|**preventExtensions**%% on **obj**. Returns **obj**.
<example>
var x = { foo: 1 };
Object.freeze(x);
x.foo = 3;
console.log(x.foo);
x.bar = 1;
console.log(x.bar);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.9
----
preventExtensions(obj : Object) : Object
Prevents new properties from being added to **obj**. Unlike %%#freeze|**freeze**%%, existing
properties can be modified. Returns **obj**.
<example>
var x = { foo: 1 };
Object.preventExtensions(x);
x.foo = 3;
console.log(x.foo);
x.bar = 1;
console.log(x.bar);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.10
----
isSealed(obj : Object) : Boolean
Returns **true** if %%#seal|**seal**%% was called on **obj**. A sealed object cannot have
new properties added to it but the value of existing properties can be changed.
<example>
var x = { foo: 1 };
Object.seal(x);
console.log(Object.isSealed(x));
console.log(Object.isExtensible(x));
console.log(Object.isFrozen(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.11
----
isFrozen(obj : Object) : Boolean
Returns **true** if %%#freeze|**freeze**%% was called on **obj**. A frozen object cannot have
new properties added and existing properties cannot be modified.
<example>
var x = { foo: 1 };
Object.freeze(x);
console.log(Object.isSealed(x));
console.log(Object.isExtensible(x));
console.log(Object.isFrozen(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.12
----
isExtensible(obj : Object) : Boolean
Returns **false** if %%#preventExtensions|**preventExtensions**%% was called on **obj**. A
non-extensible object cannot have new properties added to it.
<example>
var x = { foo: 1 };
console.log(Object.isExtensible(x));
Object.preventExtensions(x);
console.log(Object.isExtensible(x));
console.log(Object.isSealed(x));
console.log(Object.isFrozen(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.13
----
keys(obj : Object) : Array<String>
Returns an **Array** containing the enumerable properties on **obj**.
See also %%#getOwnPropertyNames|**getOwnPropertyNames()**%%.
<example>
var x = { foo: 1, bar: 2 };
console.log(Object.keys(x));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.14
----
prototype.constructor : Function
The **Function** that constructed **this**.
<example>
console.log({}.constructor === Object);
console.log([].constructor === Array);
console.log('foo'.constructor === String);
</example>
----
prototype.toString() : String
Returns a string representation of **this**. This method is called
each time the object is used in a place a string is expected. Define your own
**toString** to give a better string representation to your objects.
<example>
var pt = { x: 1, y: 2 };
console.log(pt);
pt.toString = function() {
return '(' + this.x + ', ' + this.y + ')';
};
console.log(pt);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2
----
prototype.toLocaleString() : String
Returns a locale specific (if possible) string representation of **this**.
<example>
var x = 1.234;
console.log(x.toString());
console.log(x.toLocaleString());
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.3
----
prototype.valueOf() : Object
For boxed primitive types, returns the unboxed value.
<example>
var x = Object(1);
console.log(x === 1);
console.log(x.valueOf() === 1);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.4
----
prototype.hasOwnProperty(propertyName : String) : Boolean
Returns **true** if **this** has a property named **propertyName** stored on it.
This method can be used to see if a property is set on the object, even
if the value is set to **undefined**.
Properties stored in the prototype chain do not count.
<example>
var x = { foo: 1 };
console.log(x.hasOwnProperty('foo'));
console.log(x.hasOwnProperty('bar'));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.5
----
prototype.isPrototypeOf(obj : Object) : Boolean
Returns **true** if **this** is in the prototype chain of **obj**.
<example>
// Array instances are Objects
console.log(Object.prototype.isPrototypeOf(Array.prototype));
// Array instances are not Functions
console.log(Function.prototype.isPrototypeOf(Array.prototype));
// Array constructor is a Function
console.log(Function.prototype.isPrototypeOf(Array));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.6
----
prototype.propertyIsEnumerable(propertyName : String) : Boolean
Returns **true** if the property named **propertyName** on **this** is
enumerable and should be returned during a **for (x in y)** loop.
<example>
var x = { foo: 1 };
Object.defineProperty(x, 'bar', { value: 2,
writable: true,
enumerable: false,
configurable: true } );
console.log(x.propertyIsEnumerable('foo'));
console.log(x.propertyIsEnumerable('bar'));
for (var propertyName in x) {
console.log(propertyName + ' is ' + x[propertyName]);
}
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.7