Name Resolution (Scope)
Function calls have the same name resolution rules as properties and callbacks. When called without an element name:
- If the element that the function is called in (
self
) defines a function with that name, it is chosen. - If not, name resolution continues to its parent element, and so on, until the root component.
When called with an element name (or self
, parent
or root
), the function must be defined on that
element. Name resolution does not look at ancestor elements in this case. Note that this means
calling a function without an element name is not equivalent to calling it with self
(which is how methods work in many languages).
Multiple functions with the same name are allowed in the same component, as long as they are defined on different elements. Therefore it is possible for a function to shadow another function from an ancestor element.
In the example above, the property secret_number
will be set to 1, and the text labels will say “The
secret number is 3” and “The other secret number is 2”.
© 2024 SixtyFPS GmbH