Merge pull request #116129 from AR-DEV-1/116086
Update the `Dictionary.get` documentation regarding the `default` argument & its side effects
This commit is contained in:
commit
003cc3d84b
1 changed files with 7 additions and 0 deletions
|
|
@ -256,6 +256,13 @@
|
|||
<param index="1" name="default" type="Variant" default="null" />
|
||||
<description>
|
||||
Returns the corresponding value for the given [param key] in the dictionary. If the [param key] does not exist, returns [param default], or [code]null[/code] if the parameter is omitted.
|
||||
[b]Note:[/b] If the [param default] argument is computationally expensive or has unwanted side effects, consider using the [method has] method instead:
|
||||
[codeblock]
|
||||
# Always calls `expensive_function()`.
|
||||
dict.get("key", expensive_function())
|
||||
# Calls `expensive_function()` only if the key does not exist.
|
||||
dict.get("key") if dict.has("key") else expensive_function()
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_or_add">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue