Prev | Current Page 199 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The result is the display of the values 0, 1, 2, 3, 4, 5, 6, 5, 4, 3,
2, 1, 0.
Local Functions
Local functions are functions that exist as the value of a variable. That is to say, you construct a function
and pass a reference of that construction to a variable. C developers might consider this the equivalent of
function pointers, and indeed, local functions can be used to provide similar functionality. The
differences between methods of a class and local functions are structural, as local functions do not have a
name. However, to some extent, both functions are interchangeable, and you ??™ ll look at ways of doing this
a little later.
Local functions take on the following structure:
var functionVariable = function( param : ParamType [, ...] ) : ReturnType
{
// function code...
}
As you can see, the brackets containing the parameters directly follow the function keyword and no
name is given. The prototype of the function is directly assigned to a variable by reference. Once
assigned, it is then possible to copy the reference to a new variable.


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