|
24 | 24 |
|
25 | 25 | @val external seal: 'a => 'a = "Object.seal"
|
26 | 26 | @val external preventExtensions: 'a => 'a = "Object.preventExtensions"
|
27 |
| -@val external freeze: 'a => 'a = "Object.freeze" |
| 27 | +/** |
| 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. `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. |
| 31 | +
|
| 32 | +Rescript usually [disallows modifying objects](https://rescript-lang.org/docs/manual/latest/object#update) regardless of whether they are frozen. |
| 33 | +
|
| 34 | + ## Examples |
| 35 | +
|
| 36 | + ```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 |
| 41 | + ``` |
| 42 | + ## Specifications |
| 43 | +- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update) |
| 44 | +- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.freeze) |
| 45 | +- [Object.freeze on Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) |
| 46 | + */ |
| 47 | +@val |
| 48 | +external freeze: 'a => 'a = "Object.freeze" |
28 | 49 |
|
29 | 50 | @val external isSealed: 'a => bool = "Object.isSealed"
|
30 |
| -@val external isFrozen: 'a => bool = "Object.isFrozen" |
| 51 | +/** |
| 52 | +`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. |
| 53 | +
|
| 54 | +## Examples |
| 55 | +
|
| 56 | +```rescript |
| 57 | +let point = {"x": 1, "y": 3}->Object.freeze |
| 58 | +let pointIsFrozen = point->Object.isFrozen // true |
| 59 | +let fruit = {"name": "Apple" } |
| 60 | +let fruitIsFrozen = fruit->Object.isFrozen // false |
| 61 | + ``` |
| 62 | + ## Specifications |
| 63 | +- [Updating objects in Rescript](https://rescript-lang.org/docs/manual/latest/object#update) |
| 64 | +- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isfrozen) |
| 65 | +- [Object.isFrozen on Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen) |
| 66 | + */ |
| 67 | +@val |
| 68 | +external isFrozen: 'a => bool = "Object.isFrozen" |
31 | 69 | @val external isExtensible: 'a => bool = "Object.isExtensible"
|
0 commit comments