Make all types support "!" so "if (!foo)" works reliably for all objects.

This commit is contained in:
Bob Nystrom
2015-01-15 21:50:01 -08:00
parent 94259fac8a
commit 64c2bd7633
10 changed files with 57 additions and 21 deletions
+16 -1
View File
@@ -29,7 +29,7 @@ Boolean values. There are two instances, `true` and `false`.
### **!** operator
Negates the value.
Returns the logical complement of the value.
> !true
false
@@ -150,6 +150,15 @@ It is a runtime error if `block` is not a function.
**TODO**
## Null Class
### **!** operator
Returns `true`, since `null` is considered [false](control-flow.html#truth).
> !null
true
## Num Class
**TODO**
@@ -242,6 +251,12 @@ It is a runtime error if `other` is not a number.
**TODO**
## Object Class
### **!** operator
Returns `false`, since most objects are considered [true](control-flow.html#truth).
## String Class
A string of Unicode code points stored in UTF-8.