mirror of
https://github.com/golang/go
synced 2024-11-27 03:41:22 -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
|
// 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 {
|
func (v Value) Truthy() bool {
|
||||||
switch v.Type() {
|
switch v.Type() {
|
||||||
case TypeUndefined, TypeNull:
|
case TypeUndefined, TypeNull:
|
||||||
@ -371,10 +371,7 @@ func (v Value) Truthy() bool {
|
|||||||
case TypeBoolean:
|
case TypeBoolean:
|
||||||
return v.Bool()
|
return v.Bool()
|
||||||
case TypeNumber:
|
case TypeNumber:
|
||||||
if v.ref == valueNaN.ref {
|
return v.ref != valueNaN.ref && v.ref != valueZero.ref
|
||||||
return false
|
|
||||||
}
|
|
||||||
return v.ref != valueZero.ref
|
|
||||||
case TypeString:
|
case TypeString:
|
||||||
return v.String() != ""
|
return v.String() != ""
|
||||||
case TypeSymbol, TypeFunction, TypeObject:
|
case TypeSymbol, TypeFunction, TypeObject:
|
||||||
|
Loading…
Reference in New Issue
Block a user