Skip to content

Commit 6d36dbf

Browse files
committed
documentation for preventExtensions
1 parent 7c2f372 commit 6d36dbf

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/Core__Object.res

+34-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,41 @@
2323
@val external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call"
2424

2525
@val external seal: 'a => 'a = "Object.seal"
26-
@val external preventExtensions: 'a => 'a = "Object.preventExtensions"
26+
/**
27+
`preventExtensions` prevents new properties from being added to the object. It modifies the object (rather than creating a copy) and returns it.
28+
29+
## Examples
30+
31+
```rescript
32+
let obj = {"a": 1}
33+
obj->Object.set("b", 2) // succeeds
34+
obj->Object.preventExtensions->ignore
35+
obj->Object.set("c", 3) // fails
36+
```
37+
## Specifications
38+
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.preventextensions)
39+
- [Object.preventExtensions on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
40+
*/
41+
@val
42+
external preventExtensions: 'a => 'a = "Object.preventExtensions"
2743
@val external freeze: 'a => 'a = "Object.freeze"
2844

2945
@val external isSealed: 'a => bool = "Object.isSealed"
3046
@val external isFrozen: 'a => bool = "Object.isFrozen"
31-
@val external isExtensible: 'a => bool = "Object.isExtensible"
47+
/**
48+
`isExtensible` determines if an object is extensible (whether it can have new properties added to it).
49+
50+
## Examples
51+
52+
```rescript
53+
let obj = {"a": 1}
54+
obj->Object.isExtensible // true
55+
obj->Object.preventExtensions->ignore
56+
obj->Object.isExtensible // false
57+
```
58+
## Specifications
59+
- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isextensible)
60+
- [Object.isExtensible on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
61+
*/
62+
@val
63+
external isExtensible: 'a => bool = "Object.isExtensible"

0 commit comments

Comments
 (0)