diff --git a/src/Core__Object.res b/src/Core__Object.res index e2e14c50..36f23f29 100644 --- a/src/Core__Object.res +++ b/src/Core__Object.res @@ -22,10 +22,43 @@ @val external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call" -@val external seal: 'a => 'a = "Object.seal" +/** +`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. + +**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. + +See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.seal) and [Object.seal on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) + +## Examples + +```rescript +let point = {"x": 1, "y": 2} +point->Object.set("x", -7) // succeeds +point->Object.seal->ignore +point->Object.set("z", 9) // fails +point->Object.set("x", 13) // succeeds +``` +*/ +@val +external seal: 'a => 'a = "Object.seal" @val external preventExtensions: 'a => 'a = "Object.preventExtensions" @val external freeze: 'a => 'a = "Object.freeze" -@val external isSealed: 'a => bool = "Object.isSealed" +/** +`isSealed` determines if an object is sealed. A sealed object has a fixed set of properties. + +See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.issealed) and [Object.isSealed on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed) + +## Examples + +```rescript +let point = {"x": 1, "y": 3}->Object.seal +let pointIsSealed = point->Object.isSealed // true +let fruit = {"name": "Apple" } +let fruitIsSealed = fruit->Object.isSealed // false + ``` +*/ +@val +external isSealed: 'a => bool = "Object.isSealed" @val external isFrozen: 'a => bool = "Object.isFrozen" @val external isExtensible: 'a => bool = "Object.isExtensible"