Callbacks vs Methods
To begin, let's quickly define two Luau terms:
- A "callback" is a function that is called in the form of
foo.bar()
. - A "method" is a function that is called in the form of
foo:bar()
.- The parameter
self
is implicitly passed as the value offoo
.
- The parameter
However, in TypeScript, all functions inside of objects are called as simply foo.bar()
. To decide whether or not a function call should compile using .
or :
, roblox-ts follows a simple set of rules:
#
Callbacks- Function declarations are considered callbacks.
- Arrow function expressions are considered callbacks.
#
Methods- Method declarations are considered methods.
- Function expressions inside of object literals are considered methods.
#
Overrides- If a function has a parameter
this: void
, it is always considered to be a callback.
- If a function has a parameter
this
which is typed as anything exceptvoid
, it is always considered to be a method.