/
Object.cljs
763 lines (527 loc) · 20.3 KB
/
Object.cljs
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
(ns js.Object
"The Object constructor creates an object wrapper."
(:refer-clojure :exclude [create keys eval]))
(defn assign
"Method.
The Object.assign() method is used to copy the values of all
own properties from one or more source objects to a target object.
will return the target object.
`Object.assign(target, ...sources)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign`"
[this & args]
(-> this .-assign (.apply this (clj->js args))))
(defn create
"Method.
The Object.create() method creates a new object, using an existing
as the prototype of the newly created object.
`Object.create(proto, [propertiesObject])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create`"
[this & args]
(-> this .-create (.apply this (clj->js args))))
(defn define-properties
"Method.
The Object.defineProperties() method defines new or modifies
properties directly on an object, returning the object.
`Object.defineProperties(obj, props)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties`"
[this obj props]
(-> this (.defineProperties obj props)))
(defn define-property
"Method.
The static method Object.defineProperty() defines a new property
on an object, or modifies an existing property on an object,
returns the object.
`Object.defineProperty(obj, prop, descriptor)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty`"
[this obj prop descriptor]
(-> this (.defineProperty obj prop descriptor)))
(defn entries
"Method.
The Object.entries() method returns an array of a given object's
enumerable string-keyed property [key, value] pairs, in the same
as that provided by a `for...in` loop (the difference being that
for-in loop enumerates properties in the prototype chain as well).
order of the array returned by Object.entries() does not depend
how an object is defined. If there is a need for certain ordering
the array should be sorted first like Object.entries(obj).sort((a,
=> b[0].localeCompare(a[0]));.
`Object.entries(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries`"
[this obj]
(-> this (.entries obj)))
(defn freeze
"Method.
The Object.freeze() method freezes an object. A frozen object
no longer be changed; freezing an object prevents new properties
being added to it, existing properties from being removed, prevents
the enumerability, configurability, or writability of existing
and prevents the values of existing properties from being changed.
addition, freezing an object also prevents its prototype from
changed. freeze() returns the same object that was passed in.
`Object.freeze(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze`"
[this obj]
(-> this (.freeze obj)))
(defn from-entries
"Method.
The Object.fromEntries() method transforms a list of key-value
into an object.
`Object.fromEntries(iterable);`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries`"
[this iterable]
(-> this (.fromEntries iterable)))
(defn get-notifier
"Method.
[Obsolute]
The Object.getNotifer() method was used to create an object that
to synthetically trigger a change, but has been deprecated and
in browsers.
`Object.getNotifier(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getNotifier`"
[this obj]
(-> this (.getNotifier obj)))
(defn get-own-property-descriptor
"Method.
The Object.getOwnPropertyDescriptor() method returns a property
for an own property (that is, one directly present on an object
not in the object's prototype chain) of a given object.
`Object.getOwnPropertyDescriptor(obj, prop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor`"
[this obj prop]
(-> this (.getOwnPropertyDescriptor obj prop)))
(defn get-own-property-descriptors
"Method.
The Object.getOwnPropertyDescriptors() method returns all own
descriptors of a given object.
`Object.getOwnPropertyDescriptors(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors`"
[this obj]
(-> this (.getOwnPropertyDescriptors obj)))
(defn get-own-property-names
"Method.
The Object.getOwnPropertyNames() method returns an array of all
(including non-enumerable properties except for those which use
found directly in a given object.
`Object.getOwnPropertyNames(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames`"
[this obj]
(-> this (.getOwnPropertyNames obj)))
(defn get-own-property-symbols
"Method.
The Object.getOwnPropertySymbols() method returns an array of
symbol properties found directly upon a given object.
`Object.getOwnPropertySymbols(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols`"
[this obj]
(-> this (.getOwnPropertySymbols obj)))
(defn get-prototype-of
"Method.
The Object.getPrototypeOf() method returns the prototype (i.e.
value of the internal [[Prototype]] property) of the specified
`Object.getPrototypeOf(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf`"
[this obj]
(-> this (.getPrototypeOf obj)))
(defn is
"Method.
The Object.is() method determines whether two values are the
value.
`Object.is(value1, value2);`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is`"
[this value1 value2]
(-> this (.is value1 value2)))
(defn is-extensible
"Method.
The Object.isExtensible() method determines if an object is extensible
it can have new properties added to it).
`Object.isExtensible(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible`"
[this obj]
(-> this (.isExtensible obj)))
(defn is-frozen
"Method.
The Object.isFrozen() determines if an object is frozen.
`Object.isFrozen(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen`"
[this obj]
(-> this (.isFrozen obj)))
(defn is-sealed
"Method.
The Object.isSealed() method determines if an object is sealed.
`Object.isSealed(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed`"
[this obj]
(-> this (.isSealed obj)))
(defn keys
"Method.
The Object.keys() method returns an array of a given object's
enumerable property names, in the same order as we get with a
loop.
`Object.keys(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys`"
[this obj]
(-> this (.keys obj)))
(defn observe
"Method.
[Obsolute]
The Object.observe() method was used for asynchronously observing
changes to an object. It provided a stream of changes in the
in which they occur. However, this API has been deprecated and
from browsers. You can use the more general `js.Proxy` object
`Object.observe(obj, callback[, acceptList])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe`"
[this & args]
(-> this .-observe (.apply this (clj->js args))))
(defn prevent-extensions
"Method.
The Object.preventExtensions() method prevents new properties
ever being added to an object (i.e. prevents future extensions
the object).
`Object.preventExtensions(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions`"
[this obj]
(-> this (.preventExtensions obj)))
(defn define-getter
"Method.
The __defineGetter__ method binds an object's property to a function
be called when that property is looked up.
`obj.__defineGetter__(prop, func)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineGetter__`"
[this prop func]
(-> this (.__defineGetter__ prop func)))
(defn define-setter
"Method.
The __defineSetter__ method binds an object's property to a function
be called when an attempt is made to set that property.
`obj.__defineSetter__(prop, fun)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__defineSetter__`"
[this prop fun]
(-> this (.__defineSetter__ prop fun)))
(defn lookup-getter
"Method.
[Deprecated]
The __lookupGetter__ method returns the function bound as a getter
the specified property.
`obj.__lookupGetter__(sprop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupGetter__`"
[this sprop]
(-> this (.__lookupGetter__ sprop)))
(defn lookup-setter
"Method.
[Deprecated]
The __lookupSetter__ method returns the function bound as a setter
the specified property.
`obj.__lookupSetter__(sprop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/__lookupSetter__`"
[this sprop]
(-> this (.__lookupSetter__ sprop)))
(defn eval
"Method.
[Obsolute]
The Object.eval() method used to evaluate a string of JavaScript
in the context of an object, however, this method has been removed.
`obj.eval(string)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/eval`"
[this string]
(-> this (.eval string)))
(defn has-own-property
"Method.
The hasOwnProperty() method returns a boolean indicating whether
object has the specified property as its own property (as opposed
inheriting it).
`obj.hasOwnProperty(prop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty`"
[this prop]
(-> this (.hasOwnProperty prop)))
(defn is-prototype-of
"Method.
The isPrototypeOf() method checks if an object exists in another
prototype chain.
`prototypeObj.isPrototypeOf(object)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf`"
[this object]
(-> this (.isPrototypeOf object)))
(defn property-is-enumerable
"Method.
The propertyIsEnumerable() method returns a Boolean indicating
the specified property is enumerable.
`obj.propertyIsEnumerable(prop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable`"
[this prop]
(-> this (.propertyIsEnumerable prop)))
(defn to-locale-string
"Method.
The toLocaleString() method returns a string representing the
This method is meant to be overridden by derived objects for
purposes.
`obj.toLocaleString()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString`"
[this ]
(-> this (.toLocaleString)))
(defn to-source
"Method.
[Non Standard]
The toSource() method returns a string representing the source
of the object.
`Object.toSource();
obj.toSource();`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toSource`"
[this & args]
(-> this .-toSource (.apply this (clj->js args))))
(defn to-string
"Method.
The toString() method returns a string representing the object.
`obj.toString()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString`"
[this ]
(-> this (.toString)))
(defn unwatch
"Method.
The unwatch() method removes a watchpoint set with the `watch()`
`obj.unwatch(prop)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/unwatch`"
[this prop]
(-> this (.unwatch prop)))
(defn value-of
"Method.
The valueOf() method returns the primitive value of the specified
`object.valueOf()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf`"
[this ]
(-> this (.valueOf)))
(defn watch
"Method.
The watch() method watches for a property to be assigned a value
runs a function when that occurs.
`obj.watch(prop, handler)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch`"
[this prop handler]
(-> this (.watch prop handler)))
(defn seal
"Method.
The Object.seal() method seals an object, preventing new properties
being added to it and marking all existing properties as non-configurable.
of present properties can still be changed as long as they are
`Object.seal(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal`"
[this obj]
(-> this (.seal obj)))
(defn set-prototype-of
"Method.
The Object.setPrototypeOf() method sets the prototype (i.e.,
internal [[Prototype]] property) of a specified object to another
or `js.null`.
`Object.setPrototypeOf(obj, prototype)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf`"
[this obj prototype]
(-> this (.setPrototypeOf obj prototype)))
(defn unobserve
"Method.
[Obsolute]
The Object.unobserve() method was used to remove observers set
`Object.observe()`, but has been deprecated and removed from
You can use the more general `js.Proxy` object instead.
`Object.unobserve(obj, callback)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/unobserve`"
[this obj callback]
(-> this (.unobserve obj callback)))
(defn values
"Method.
The Object.values() method returns an array of a given object's
enumerable property values, in the same order as that provided
a `for...in` loop (the difference being that a for-in loop enumerates
in the prototype chain as well).
`Object.values(obj)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values`"
[this obj]
(-> this (.values obj)))
(defn prototype
"Property.
The Object.prototype is a property of the `js.Object` constructor.
is also the end of a prototype chain.
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype`"
[this]
(-> this (.-prototype)))
(defn set-prototype!
"Property.
The Object.prototype is a property of the `js.Object` constructor.
is also the end of a prototype chain.
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype`"
[this val]
(aset this "prototype" val))
(defn count
"Property.
[Non Standard]
[Obsolute]
The __count__ property used to store the count of enumerable
on the object, but it has been removed.
`obj.__count__`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/count`"
[this]
(-> this (.-__count__)))
(defn set-count!
"Property.
[Non Standard]
[Obsolute]
The __count__ property used to store the count of enumerable
on the object, but it has been removed.
`obj.__count__`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/count`"
[this val]
(aset this "__count__" val))
(defn no-such-method
"Property.
[Non Standard]
[Obsolute]
The __noSuchMethod__ property used to reference a function to
executed when a non-existent method is called on an object, but
function is no longer available.
`obj.__noSuchMethod__ = fun`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/noSuchMethod`"
[this]
(-> this (.-__noSuchMethod__)))
(defn set-no-such-method!
"Property.
[Non Standard]
[Obsolute]
The __noSuchMethod__ property used to reference a function to
executed when a non-existent method is called on an object, but
function is no longer available.
`obj.__noSuchMethod__ = fun`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/noSuchMethod`"
[this val]
(aset this "__noSuchMethod__" val))
(defn parent
"Property.
[Non Standard]
[Obsolute]
The __parent__ property used to point to an object's context,
it has been removed.
`obj.__parent__`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/Parent`"
[this]
(-> this (.-__parent__)))
(defn set-parent!
"Property.
[Non Standard]
[Obsolute]
The __parent__ property used to point to an object's context,
it has been removed.
`obj.__parent__`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/Parent`"
[this val]
(aset this "__parent__" val))
(defn proto
"Property.
[Deprecated]
The __proto__ property of `Object.prototype` is an accessor property
getter function and a setter function) that exposes the internal
(either an object or `js.null`) of the object through which it
accessed.
`var Circle = function () {};
var shape = {};
var circle = new Circle();
// Set the object prototype.
// DEPRECATED. This is for example purposes only. DO NOT DO THIS in real code.
shape.__proto__ = circle;
// Get the object prototype
console.log(shape.__proto__ === circle); // true
var shape = function () {};
var p = {
a: function () {
console.log('aaa');
}
};
shape.prototype.__proto__ = p;
var circle = new shape();
circle.a(); // aaa
console.log(shape.prototype === circle.__proto__); // true
// or
var shape = function () {};
var p = {
a: function () {
console.log('a');
}
};
var circle = new shape();
circle.__proto__ = p;
circle.a(); // a
console.log(shape.prototype === circle.__proto__); // false
// or
function test() {};
test.prototype.myname = function () {
console.log('myname');
};
var a = new test();
console.log(a.__proto__ === test.prototype); // true
a.myname(); // myname
// or
var fn = function () {};
fn.prototype.myname = function () {
console.log('myname');
};
var obj = {
__proto__: fn.prototype
};
obj.myname(); // myname
Note: that is two underscores, followed by the five characters \\\"proto\\\", followed by two more underscores.`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto`"
[this]
(-> this (.-__proto__)))
(defn set-proto!
"Property.
[Deprecated]
The __proto__ property of `Object.prototype` is an accessor property
getter function and a setter function) that exposes the internal
(either an object or `js.null`) of the object through which it
accessed.
`var Circle = function () {};
var shape = {};
var circle = new Circle();
// Set the object prototype.
// DEPRECATED. This is for example purposes only. DO NOT DO THIS in real code.
shape.__proto__ = circle;
// Get the object prototype
console.log(shape.__proto__ === circle); // true
var shape = function () {};
var p = {
a: function () {
console.log('aaa');
}
};
shape.prototype.__proto__ = p;
var circle = new shape();
circle.a(); // aaa
console.log(shape.prototype === circle.__proto__); // true
// or
var shape = function () {};
var p = {
a: function () {
console.log('a');
}
};
var circle = new shape();
circle.__proto__ = p;
circle.a(); // a
console.log(shape.prototype === circle.__proto__); // false
// or
function test() {};
test.prototype.myname = function () {
console.log('myname');
};
var a = new test();
console.log(a.__proto__ === test.prototype); // true
a.myname(); // myname
// or
var fn = function () {};
fn.prototype.myname = function () {
console.log('myname');
};
var obj = {
__proto__: fn.prototype
};
obj.myname(); // myname
Note: that is two underscores, followed by the five characters \\\"proto\\\", followed by two more underscores.`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto`"
[this val]
(aset this "__proto__" val))