Skip to content

Commit bfa541f

Browse files
committed
better code examples
1 parent 5b95915 commit bfa541f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Core__Object.res

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@
2323
@val external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call"
2424

2525
/**
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.
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.
2927
30-
Rescript usually [disallows modifying objects](https://rescript-lang.org/docs/manual/latest/object#update) regardless of whether they are sealed.
28+
**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.
3129
3230
## Examples
3331
3432
```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
33+
let point = {"x": 1, "y": 2}
34+
point->Object.set("x", -7) // succeeds
35+
point->Object.seal->ignore
36+
point->Object.set("z", 9) // fails
37+
point->Object.set("x", 13) // succeeds
3938
```
4039
## Specifications
4140
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)

0 commit comments

Comments
 (0)