Learning Haxe: Part 5: Functions

Learning Haxe

Haxe is a strongly-typed multi-paradigm programming language that also supports cross-platform compiling into many different source and byte-code languages such as ActionScript 3, JavaScript, Java, C++, C#, PHP, Python, Lua, and Node.js.


In Haxe, functions follow a similar structure to conditional statements and variables. They have a name, a set of zero or more arguments, and code within open and closed curly brackets.

Like variables, functions also have a type.

The type of a function is its return type. This is the type of the value that will be returned from the function. It follows the name and arguments with a colon and then the type.


A function is defined through using the function keyword. The name of the function follows the keyword.


Haxe uses the terminology of arguments for passing data into a function. These, like other variables, must have a type that defines them. They are within open and closed parentheses.

Optional Arguments

Haxe support optional arguments. In programming terminology, these are values defined within the parentheses with initial values. If a value is not passed into the function (thus making it optional), the variable takes this value.

Private Function, Public Method

As discussed in the section on Objects, a function is private. If the public keyword is used with a function, it becomes a method of an object.