Skip to content

Commit 6490abd

Browse files
committed
Merge branch 'Object.is' into Object-docs
2 parents 49537f2 + 08db9a8 commit 6490abd

File tree

5 files changed

+508
-4
lines changed

5 files changed

+508
-4
lines changed

src/Core__Object.res

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
@obj external empty: unit => {..} = ""
22

3-
@val external is: ('a, 'b) => bool = "Object.is"
3+
/**
4+
`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, and strings are identical if they have the same value. `+0` and `-0` are distinct. NaN is equal to itself. See [Object.is on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
5+
6+
In most scenarios use `==` or `===` or the custom `equals` function (if provided) for the type.
7+
8+
## Examples
9+
10+
```rescript
11+
Object.is(25, 13) // false
12+
Object.is("abc", "abc") // true
13+
Object.is(undefined, undefined) // true
14+
Object.is(undefined, null) // false
15+
Object.is(-0.0, 0.0) // false
16+
Object.is(list{1, 2}, list{1, 2}) // false
17+
18+
Object.is([1, 2, 3], [1, 2, 3]) // false
19+
[1, 2, 3] == [1, 2, 3] // true
20+
[1, 2, 3] === [1, 2, 3] // false
21+
22+
let fruit = {"name": "Apple" }
23+
Object.is(fruit, fruit) // true
24+
Object.is(fruit, {"name": "Apple" }) // false
25+
fruit == {"name": "Apple" } // true
26+
fruit === {"name": "Apple" } // false
27+
```
28+
*/
29+
@val
30+
external is: ('a, 'a) => bool = "Object.is"
431

532
@val external create: {..} => {..} = "Object.create"
633
@val external createWithProperties: ({..}, {..}) => {..} = "Object.create"

0 commit comments

Comments
 (0)