Skip to content

Commit 5b95915

Browse files
committed
seal and isSealed documentation
1 parent 7c2f372 commit 5b95915

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/Core__Object.res

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,48 @@
2222

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

25-
@val external seal: 'a => 'a = "Object.seal"
25+
/**
26+
`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. `seal` returns the same object that was passed in.
27+
28+
Any attempt to delete or add properties to a sealed object will fail, either silently or by throwing an error.
29+
30+
Rescript usually [disallows modifying objects](https://rescript-lang.org/docs/manual/latest/object#update) regardless of whether they are sealed.
31+
32+
## Examples
33+
34+
```rescript
35+
let point = {"x": 1, "y": 3}->Object.seal
36+
let pointIsSealed = point->Object.isSealed // true
37+
let fruit = {"name": "Apple" }
38+
let fruitIsSealed = fruit->Object.isSealed // false
39+
```
40+
## Specifications
41+
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
42+
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.seal)
43+
- [Object.seal on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
44+
*/
45+
@val
46+
external seal: 'a => 'a = "Object.seal"
2647
@val external preventExtensions: 'a => 'a = "Object.preventExtensions"
2748
@val external freeze: 'a => 'a = "Object.freeze"
2849

29-
@val external isSealed: 'a => bool = "Object.isSealed"
50+
/**
51+
`isSealed` determines if an object is sealed. A sealed object has a fixed set of properties.
52+
53+
## Examples
54+
55+
```rescript
56+
let point = {"x": 1, "y": 3}->Object.seal
57+
let pointIsSealed = point->Object.isSealed // true
58+
let fruit = {"name": "Apple" }
59+
let fruitIsSealed = fruit->Object.isSealed // false
60+
```
61+
## Specifications
62+
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
63+
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.issealed)
64+
- [Object.isSealed on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
65+
*/
66+
@val
67+
external isSealed: 'a => bool = "Object.isSealed"
3068
@val external isFrozen: 'a => bool = "Object.isFrozen"
3169
@val external isExtensible: 'a => bool = "Object.isExtensible"

0 commit comments

Comments
 (0)