From 6d36dbfa48fb8d7c85e19b1732f202557a941e59 Mon Sep 17 00:00:00 2001 From: jmagaram Date: Thu, 16 Mar 2023 23:49:53 -0700 Subject: [PATCH 1/2] documentation for preventExtensions --- src/Core__Object.res | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Core__Object.res b/src/Core__Object.res index e2e14c50..1e95ef89 100644 --- a/src/Core__Object.res +++ b/src/Core__Object.res @@ -23,9 +23,41 @@ @val external hasOwnProperty: ({..}, string) => bool = "Object.prototype.hasOwnProperty.call" @val external seal: 'a => 'a = "Object.seal" -@val external preventExtensions: 'a => 'a = "Object.preventExtensions" +/** +`preventExtensions` prevents new properties from being added to the object. It modifies the object (rather than creating a copy) and returns it. + +## Examples + +```rescript +let obj = {"a": 1} +obj->Object.set("b", 2) // succeeds +obj->Object.preventExtensions->ignore +obj->Object.set("c", 3) // fails +``` +## Specifications +- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.preventextensions) +- [Object.preventExtensions on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions) +*/ +@val +external preventExtensions: 'a => 'a = "Object.preventExtensions" @val external freeze: 'a => 'a = "Object.freeze" @val external isSealed: 'a => bool = "Object.isSealed" @val external isFrozen: 'a => bool = "Object.isFrozen" -@val external isExtensible: 'a => bool = "Object.isExtensible" +/** + `isExtensible` determines if an object is extensible (whether it can have new properties added to it). + + ## Examples + + ```rescript +let obj = {"a": 1} +obj->Object.isExtensible // true +obj->Object.preventExtensions->ignore +obj->Object.isExtensible // false +``` +## Specifications +- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isextensible) +- [Object.isExtensible on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible) +*/ +@val +external isExtensible: 'a => bool = "Object.isExtensible" From a37c1b810a68aa8ce484d41854114200f8a98dce Mon Sep 17 00:00:00 2001 From: jmagaram Date: Tue, 21 Mar 2023 10:56:46 -0700 Subject: [PATCH 2/2] remove Specifications section in docs --- src/Core__Object.res | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Core__Object.res b/src/Core__Object.res index 1e95ef89..351db51f 100644 --- a/src/Core__Object.res +++ b/src/Core__Object.res @@ -26,6 +26,8 @@ /** `preventExtensions` prevents new properties from being added to the object. It modifies the object (rather than creating a copy) and returns it. +See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.preventextensions) and [Object.preventExtensions on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions) + ## Examples ```rescript @@ -34,9 +36,6 @@ obj->Object.set("b", 2) // succeeds obj->Object.preventExtensions->ignore obj->Object.set("c", 3) // fails ``` -## Specifications -- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.preventextensions) -- [Object.preventExtensions on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions) */ @val external preventExtensions: 'a => 'a = "Object.preventExtensions" @@ -45,19 +44,18 @@ external preventExtensions: 'a => 'a = "Object.preventExtensions" @val external isSealed: 'a => bool = "Object.isSealed" @val external isFrozen: 'a => bool = "Object.isFrozen" /** - `isExtensible` determines if an object is extensible (whether it can have new properties added to it). +`isExtensible` determines if an object is extensible (whether it can have new properties added to it). + +See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isextensible) and [Object.isExtensible on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible) - ## Examples +## Examples - ```rescript +```rescript let obj = {"a": 1} obj->Object.isExtensible // true obj->Object.preventExtensions->ignore obj->Object.isExtensible // false ``` -## Specifications -- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.isextensible) -- [Object.isExtensible on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible) */ @val external isExtensible: 'a => bool = "Object.isExtensible"