As you can see from the example, the type of the functions for the parameters
Chapter 4: Controlling the Flow of Information
93
was specified as Dynamic . This is because both functions take a function as their second parameter,
which takes a function as their second parameter, which takes a function as their second parameter and
so on, forming a recursive type specification. Leaving the typing to type inference results in an error, so
assigning a Dynamic type is the only remaining suitable option. If you want to add some level of control
over this type of function type definition, you could always specify the function type structure once for
the variable, but specify the recursive function type as dynamic, ensuring that a function type is at least
guaranteed to be passed on the first invocation. This will at least allow for proper usage of your function
while delegating any further type checking to the object making the call.
Local Function Variable Scope
The variable scope for local functions includes static variables of the container class, variables that have
been declared in the same level as the variable holding the function reference, and the variables that are
declared inside the function:
class LocalFunctionVars
{
public static var myStaticVar1 : String;
public var myVar1 : String;
public static function main()
{
var myLocalVar1 : String;
var myFunction = function()
{
var innerFunction : String;
innerFunction = ???haXe???;
myLocalVar1 = ???is???;
myStaticVar1 = ???really???;
// will throw a compiler error
myVar1 = ???amazing???;
}
}
}
This covers most of the variables in the class, but doesn ??™ t account for the non - static variable myVar1 .
Pages:
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215