Prev | Current Page 194 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

This means that parameters that are type inferred won ??™ t have a type until
a value has been passed to the function for this parameter. Once passed, the parameter is then typed
with the values type from then onward.
This can cause a slight issue depending on the type of the value first sent to the function. For example:
public static function main()
{
display( 2 );
display( 2.5 );
}
public static function display( num )
{
trace( num );
}
Apart from being fairly useless, the display function poses a problem. You know that the type Int is an
extension of the type Float , so a parameter that is typed as a Float should be able to accept either type,
but if you first pass an Int type to the function for the parameter, the parameter will then be typed as an
Int so Float s will no longer be accepted. The only secure way around this issue is to append the type
Float to the num parameters prototype rather than leave the typing to type inference.
Dynamic Functions
Using the Dynamic type comes into its own when used with functions.


Pages:
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206