mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add more notes about short circuiting, include equivalent if-else expressions
This commit is contained in:
parent
278775ad23
commit
3955bcb2e3
1 changed files with 10 additions and 3 deletions
|
@ -77,9 +77,16 @@ Failing the nil-safety check early would make the entire expression nil, for ins
|
|||
The list of valid operators to follow the safe navigation operator would be:
|
||||
|
||||
```lua
|
||||
dog?.name
|
||||
dog?.getName()
|
||||
dog?:getName()
|
||||
dog?.name == if dog == nil then nil else dog.name
|
||||
dog?.getName() == if dog == nil then nil else dog.getName()
|
||||
dog?:getName(args) == if dog == nil then nil else dog:getName(args)
|
||||
```
|
||||
|
||||
When using safe navigation to call a function, the short circuiting will prevent the arguments from being evaluated in the case of nil.
|
||||
|
||||
```lua
|
||||
-- Will NOT call getValue() if `object` is nil
|
||||
object?.doSomething(getValue())
|
||||
```
|
||||
|
||||
The operator must be used in the context of either a call or an index, and so:
|
||||
|
|
Loading…
Add table
Reference in a new issue