docs: document is operator as overridable infix method and add type-test examples

This commit is contained in:
Bob Nystrom
2015-11-07 21:00:24 +00:00
parent efcc4d07c7
commit f27fff9dd0
5 changed files with 30 additions and 4 deletions
+20 -3
View File
@@ -3,7 +3,7 @@
## Static Methods
## **same**(obj1, obj2)
### **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
@@ -20,7 +20,9 @@ even on user-defined classes.
### **!** operator
Returns `false`, since most objects are considered [true](control-flow.html#truth).
Returns `false`, since most objects are considered [true][].
[true]: control-flow.html#truth
### **==**(other) and **!=**(other) operators
@@ -28,10 +30,25 @@ 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.
### **is**(class) operator
Returns `true` if this object's class or one of its superclasses is `class`.
:::wren
System.print(123 is Num) //> true
System.print("s" is Num) //> false
System.print(null is String) //> false
System.print([] is List) //> true
System.print([] is Sequence) //> true
It is a runtime error if `class` is not a [Class][].
### **toString**
A default string representation of the object.
### **type**
The [Class](#class-class) of the object.
The [Class][] of the object.
[class]: class.html