You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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. `freeze` returns the same object that was passed in; it does not create a frozen copy.
29
-
30
-
Any attempt to change a frozen object will fail, either silently or by throwing an exception.
28
+
`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.
31
29
32
-
Rescript usually [disallows modifying objects](https://rescript-lang.org/docs/manual/latest/object#update) regardless of whether they are frozen.
30
+
**Note:** `freeze` returns the same object that was passed in; it does not create a frozen copy. Any attempt to change a frozen object will fail, either silently or by throwing an exception.
33
31
34
32
## Examples
35
33
36
34
```rescript
37
-
let point = {"x": 1, "y": 3}->Object.freeze
38
-
let pointIsFrozen = point->Object.isFrozen // true
39
-
let fruit = {"name": "Apple" }
40
-
let fruitIsFrozen = fruit->Object.isFrozen // false
35
+
let obj = {"a": 1}
36
+
obj->Object.set("a", 2) // succeeds
37
+
obj->Object.freeze->ignore
38
+
obj->Object.set("a", 3) // fails
41
39
```
42
40
## Specifications
43
-
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
44
41
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.freeze)
45
42
- [Object.freeze on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
43
+
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
46
44
*/
47
45
@val
48
46
externalfreeze: 'a=>'a="Object.freeze"
@@ -60,9 +58,9 @@ let fruit = {"name": "Apple" }
60
58
let fruitIsFrozen = fruit->Object.isFrozen // false
61
59
```
62
60
## Specifications
63
-
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
64
61
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isfrozen)
65
62
- [Object.isFrozen on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
63
+
- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update)
0 commit comments