mirror of
https://github.com/golang/go
synced 2024-11-27 03:31:29 -07:00
More updates after code review
- Update Truthy documentation - Streamline TypeNumber case of Truthy
This commit is contained in:
parent
d8f466ac33
commit
649b353ebc
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user