With which version of AutoHotkey did you test this code?
With v2.0-a104, the second MsgBox is blank due to a bug
. This is fixed by commit 1080a00
, which is not part of any release. Did you compile it yourself?
With v2.0-a103 and earlier, a load time error is shown because static
cannot be applied to methods.
With v2.0-a101 and earlier, the fat arrow syntax is not applicable to methods or top-level functions.
The topic kczx3 refers to was initially about fat arrow functions within an expression
which can already contain global variable references. The last post (as of now) precedes the addition of fat arrow methods (and non-expression fat arrow function definitions).
The primary purpose of a fat arrow function is to allow the definition of a function within a function call, such as for passing a callback to SetTimer or similar. In this context, it is usually desirable for the function to be able to refer to variables from the same scope as the expression it is written within. If the expression is not inside a function, that is global scope.
Fat arrow methods have only the purpose of saving space. They are already set apart from functions as they have a hidden this
parameter, and are attached to instances or the class itself (always with a name). Fat arrow methods cannot be defined within (and are not) expressions.
There probably is more value in fat arrow methods being assume-local than assume-global.
Regardless, the y in Func and in Func2 cannot refer to the same variable unless it is declared super-global. Func and Func2 do not share any scope other than global; they share context only through the hidden this
parameter (and in a very limited way, base
when used for super-class calls).