|
1 | 1 | @obj external empty: unit => {..} = ""
|
2 | 2 |
|
3 |
| -@val external is: ('a, 'b) => bool = "Object.is" |
| 3 | +/** |
| 4 | +`Object.is` determines if two objects are identical in all contexts. Objects, arrays, records, and other non-primitives are only identical if they reference the **exact** same object in memory. Primitives like ints, floats, bools, and strings are identical if they have the same value. |
| 5 | +
|
| 6 | +**Note:** In most scenarios use `==` and `===`. If the data type you want to compare by value has an `equals` function, use it. |
| 7 | +
|
| 8 | +The `==` operator is different in ReScript than Javascript. Non-primitives like arrays and records are considered equal if they have the same contents. |
| 9 | +
|
| 10 | +In ReScript, the `===` operator performs a strict equality check, like Javascript, and is similar to (but not idential to) `Object.is`. See the references. |
| 11 | +
|
| 12 | +## Examples |
| 13 | +```rescript |
| 14 | +Object.is(25, 13) // false |
| 15 | +Object.is("abc", "abc") // true |
| 16 | +Object.is(undefined, undefined) // true |
| 17 | +Object.is(undefined, null) // false |
| 18 | +Object.is(-0.0, 0.0) // false |
| 19 | +Object.is(list{1, 2}, list{1, 2}) // false |
| 20 | +
|
| 21 | +let fruit = {"name": "Apple" } |
| 22 | +Object.is(fruit, fruit) // true |
| 23 | +Object.is(fruit, {"name": "Apple" }) // false |
| 24 | +fruit == {"name": "Apple" } // true |
| 25 | +fruit === {"name": "Apple" } // false |
| 26 | +
|
| 27 | +Object.is([1, 2, 3], [1, 2, 3]) // false |
| 28 | +[1, 2, 3] == [1, 2, 3] // true |
| 29 | +[1, 2, 3] === [1, 2, 3] // false |
| 30 | +``` |
| 31 | +## Specifications |
| 32 | +- [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.is) |
| 33 | +- [`Object.is on Mozilla`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) |
| 34 | +*/ |
| 35 | +@val |
| 36 | +external is: ('a, 'b) => bool = "Object.is" |
4 | 37 |
|
5 | 38 | @val external create: {..} => {..} = "Object.create"
|
6 | 39 | @val external createWithProperties: ({..}, {..}) => {..} = "Object.create"
|
|
0 commit comments