🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
Haxe supports first-class functions and allows declaring local functions in expressions. The syntax follows class field methods (4.3): ~~~ class Main { static public function main() { var value = 1; function myLocalFunction(i) { return value + i; } trace(myLocalFunction(2)); // 3 } } ~~~ We declare myLocalFunction inside the block expression (5.1) of the main class field. It takes one argument i and adds it to value, which is defined in the outside scope. The scoping is equivalent to that of variables (5.10) and for the most part writing a named local function can be considered equal to assigning an unnamed local function to a local variable: ~~~ var myLocalFunction = function(a) { } ~~~ However, there are some differences related to type parameters and the position of the function. We speak of a “lvalue” function if it is not assigned to anything upon its declaration, and an “rvalue” function otherwise. * Lvalue functions require a name and can have type parameters (3.2). * Rvalue functions may have a name, but cannot have type parameters.