Wish to overload ?? when a object's property is undefined.
Posted: 16 Dec 2022, 06:52
@Lexicos Wish to overload ?? when a object's property is undefined.
See this code:
It can be almost equivalently replaced by x:=a??0 as the alternative.
Therefore, the other nearly the same code, should be replaced by x:={}.a??0 too.
Obviously, codes have been reduced and more uniform if ?? is extendsed.
It's worth mentioning that ?? can only ignore the exception which is near ??. For example, x:=myVar.a??0, in this situation, ?? can only handle a but can not handle myVar if myVar is also unset.
See this code:
Code: Select all
try{
x:=a
}catch UnsetError{
x:=0
}
Therefore, the other nearly the same code, should be replaced by x:={}.a??0 too.
Code: Select all
try{
x:={}.a
}catch UnsetError{
x:=0
}
It's worth mentioning that ?? can only ignore the exception which is near ??. For example, x:=myVar.a??0, in this situation, ?? can only handle a but can not handle myVar if myVar is also unset.