Yes, you are right, this article is not about ECMAScript.
Currently VB 14 is more than C # 6 leading features, there is a feature that will be implemented in C # 7, called "Local Method". The difference between this feature and anonymous delegation is that anonymous delegates cannot be stored directly into a variable of the auto-inferred type (in C # as Var) and must be assigned to a variable that already has the specified delegate type, or passed as a parameter. and anonymous delegates are not allowed to be declared as iterators.
Using this feature, you can easily copy the online js/es code to use the delegate, but pay attention to using closures to circumvent some unintended results.
The local method captures the variables of the context just like any other lambda expression or anonymous delegate.
Members inside the local method cannot be accessed externally because the variable has the same name.
If you do not use the Dim keyword and Option Explicit Off, then no declaration variable will be a method-level variable. Note that this is not a global variable.
So, how do you get the variables inside the local method out?
Then you need to define another local method
The result of the execution is a popup message box with a content of 999.
So what's the practical purpose of this notation?
Execution Result: message box content: 999, message box contents: 1000
The F2 in this code takes out the n variables defined in the F1. The delegate nadd modifies the value of the variable n defined in F1.
This notation is valid in the local method, because all variables defined in the local method are stored by the class wrapper with the name similar to _closure$__2-0 and then placed in the variable area of the normal method where it resides.
After the normal method that contains the local method executes, the variable wrapper class such as_closure$__2-0 is detached from the scope, causing the variables in the local method defined in the method to be recycled at any time by GC.
warning : These should not be used in the final release of the product, because late binding can cause performance problems, and not declaring variables will give your code a bunch of warnings (green lines).
Leave a two study questions .
First question: What does the message box say?
Hint: The Green Wave is vs tells you that it might not be the same as you think.
The second question: What does the message box say?
It's not a clue.
VB 2015 Closure (Closure)