Prev | Current Page 201 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Here ??™ s an example:
var fun1 = function() : Void
{
// code...
}
var fun2 = function( p1 : String ) : Void
{
// code...
}
var fun3 = function( p1 : Int, p2 : Float, p3 : Int ) : String
{
// code...
return someString;
}
If you were to declare these variables before assigning the function references, you would do so like this:
var fun1 : Void - > Void;
var fun2 : String - > Void;
var fun3 : Int - > Float - > Int - > String;
In the first example, fun1 , there are no parameters in the function definition, so Void is used. If,
however, the function was to expect one or more parameters of type Void , they should be parenthesized,
like this:
var fun1 : (Void) - > (Void) - > Void;
fun1 = function( p1 : Void, p2 : Void ) : Void
{
// do code...
}
92
Part I: The Core Language
Passing Functions to Local Functions
One of the primary purposes of local variables is that they can be passed to other functions as
parameters. Local functions can accept other local functions as their parameters. When doing so, the
types of the parameterized function must be specified in the parameter type of the receiving function.


Pages:
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213