mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Add Object.same(_,_) to access built-in equality even for classes that may override ==.
Had to add a new metaclass for Object since it now has its own static method so we can't just use Class as its metaclass. (We don't want *every* class to have a same(_,_) static method.)
This commit is contained in:
@ -1,6 +1,21 @@
|
||||
^title Object Class
|
||||
^category core
|
||||
|
||||
## Static Methods
|
||||
|
||||
## **same**(obj1, obj2)
|
||||
|
||||
Returns `true` if *obj1* and *obj2* are the same. For [value
|
||||
types](../values.html), this returns `true` if the objects have equivalent
|
||||
state. In other words, numbers, strings, booleans, and ranges compare by value.
|
||||
|
||||
For all other objects, this returns `true` only if *obj1* and *obj2* refer to
|
||||
the exact same object in memory.
|
||||
|
||||
This is similar to the built in `==` operator in Object except that this cannot
|
||||
be overriden. It allows you to reliably access the built-in equality semantics
|
||||
even on user-defined classes.
|
||||
|
||||
## Methods
|
||||
|
||||
### **!** operator
|
||||
@ -9,9 +24,9 @@ Returns `false`, since most objects are considered [true](control-flow.html#trut
|
||||
|
||||
### **==**(other) and **!=**(other) operators
|
||||
|
||||
Compares two objects using built-in equality. This compares numbers by value,
|
||||
and all other objects are compared by identity—two objects are equal only
|
||||
if they are the exact same object.
|
||||
Compares two objects using built-in equality. This compares [value
|
||||
types](../values.html) by value, and all other objects are compared by
|
||||
identity—two objects are equal only if they are the exact same object.
|
||||
|
||||
### **toString**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user