1
0
mirror of https://github.com/golang/go synced 2024-11-27 01:11:20 -07:00

More updates after code review

- Update Truthy documentation
- Streamline TypeNumber case of Truthy
This commit is contained in:
Larry Clapp 2018-10-25 21:27:54 -04:00
parent d8f466ac33
commit 649b353ebc

View File

@ -361,9 +361,9 @@ func (v Value) Bool() bool {
}
}
// Truthy returns the JavaScript "truthiness" of the value v. In JavaScript,
// Truthy returns the JavaScript "truthiness" of the value v. In JavaScript,
// false, 0, "", null, undefined, and NaN are "falsy", and everything else is
// "truthy". See https://developer.mozilla.org/en-US/docs/Glossary/Truthy.
// "truthy". See https://developer.mozilla.org/en-US/docs/Glossary/Truthy.
func (v Value) Truthy() bool {
switch v.Type() {
case TypeUndefined, TypeNull:
@ -371,10 +371,7 @@ func (v Value) Truthy() bool {
case TypeBoolean:
return v.Bool()
case TypeNumber:
if v.ref == valueNaN.ref {
return false
}
return v.ref != valueZero.ref
return v.ref != valueNaN.ref && v.ref != valueZero.ref
case TypeString:
return v.String() != ""
case TypeSymbol, TypeFunction, TypeObject: