|
Spec-Zone .ru
спецификации, руководства, описания, API
|
Functions can be declared at the script level (script function) or inside a class (instance function). Local functions are not yet supported.
Script functions are declared at the top-level of a script, not inside a class definition. Script functions are visible throughout the entire script -- a member access expression is not needed.
function square(x : Number) : Number { x * x }
println( square(7) )
If access modifiers are added which make the script function visible outside the script, they may be accessed as members of the script. For example, if this is script Foo.fx:
public function square(x : Number) : Number { x * x }
Then script Bar.fx can access square:
println(Foo.square(10))
Instance functions are declared at the top-level of a class. Instance functions are visible through-out the entire script -- a member access expression is not needed within the class (or its subclasses) but is needed outside of the class.
class Scale {
var factor : Number;
function transform(x : Number) : Number { factor * x }
}
var tf = Scale { factor: 25.0 }
println(tf.transform(10.0))