Skip to content

Commit 23d7f0e

Browse files
committed
Merge branch 'Object.seal-and-Object.isSealed' into Object-docs
2 parents c8a7ce5 + b37ce6b commit 23d7f0e

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/Core__Object.res

+38-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,28 @@ external is: ('a, 'a) => bool = "Object.is"
4949

5050
@val external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call"
5151

52-
@val external seal: 'a => 'a = "Object.seal"
52+
/**
53+
`seal` seals an object. Sealing an object prevents extensions and makes existing properties non-configurable. A sealed object has a fixed set of properties. Unlike `freeze`, values of existing properties can still be changed as long as they are writable.
54+
55+
**Note:** `seal` returns the same object that was passed in; it does not create a copy. Any attempt to delete or add properties to a sealed object will fail, either silently or by throwing an error.
56+
57+
See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.seal) and [Object.seal on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
58+
59+
## Examples
60+
61+
```rescript
62+
let point = {"x": 1, "y": 2}
63+
point->Object.set("x", -7) // succeeds
64+
point->Object.seal->ignore
65+
point->Object.set("z", 9) // fails
66+
point->Object.set("x", 13) // succeeds
67+
```
68+
*/
69+
@val
70+
external seal: 'a => 'a = "Object.seal"
71+
5372
@val external preventExtensions: 'a => 'a = "Object.preventExtensions"
73+
5474
/**
5575
`freeze` freezes an object. Freezing an object makes existing properties non-writable and prevents extensions. Once an object is frozen, new properties cannot be be added, existing properties cannot be removed, and their values cannot be changed.
5676
@@ -70,7 +90,23 @@ obj->Object.set("a", 3) // fails
7090
@val
7191
external freeze: 'a => 'a = "Object.freeze"
7292

73-
@val external isSealed: 'a => bool = "Object.isSealed"
93+
/**
94+
`isSealed` determines if an object is sealed. A sealed object has a fixed set of properties.
95+
96+
See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.issealed) and [Object.isSealed on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
97+
98+
## Examples
99+
100+
```rescript
101+
let point = {"x": 1, "y": 3}->Object.seal
102+
let pointIsSealed = point->Object.isSealed // true
103+
let fruit = {"name": "Apple" }
104+
let fruitIsSealed = fruit->Object.isSealed // false
105+
```
106+
*/
107+
@val
108+
external isSealed: 'a => bool = "Object.isSealed"
109+
74110
/**
75111
`isFrozen` determines if an object is frozen. An object is frozen if an only if it is not extensible, all its properties are non-configurable, and all its data properties are non-writable.
76112

0 commit comments

Comments
 (0)