|
Spec-Zone .ru
спецификации, руководства, описания, API
|
A function type represents the set of function definitions with a given signature -- that is, the functions which have the given parameter types and return type.
For example, the variable myFunc is declared as being of a function type:
var myFunc : function(:Object,:Integer):String;
The variable myFunc can hold function definitions which take an Object and an Integer as parameters and returns a String.
Function types have null as their default value. So, myFunc is initially null, we can give it a value by assignment or initialization. This would be a valid assignment to myFunc:
myFunc = function(obj : Object, k : Integer) { "Here is the Object: {obj}, and the Integer: {k}" }
The function definition currently held in myFunc can be called like any other function:
println( myFunc(4s, 777) ); println( myFunc(null, 1234) );
Which would print:
Here is the Object: 4000.0ms, and the Integer: 777 Here is the Object: null, and the Integer: 1234
The variable, of course, can be reassigned to any function with those parameters and return type:
myFunc = function(obj : Object, k : Integer) { "So!" }