Go Closures: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
A closure is an anonymous function declared within a block. The function has access to the local variables for the duration of its life. | A closure is an anonymous function declared within a block. The function has access to the local variables for the duration of its life. | ||
<pre> | |||
inClosuresScope := 10 | |||
var c = func (i int) { | |||
inClosuresScope += i | |||
} | |||
s := []int {1, 2, 3, 4, 5, 6} | |||
for _, value := range s { | |||
c(value); | |||
} | |||
</pre> | |||
More about closures is available [[Programming#Closures|here]]. | More about closures is available [[Programming#Closures|here]]. |
Revision as of 04:31, 28 March 2016
Internal
Overview
A closure is an anonymous function declared within a block. The function has access to the local variables for the duration of its life.
inClosuresScope := 10 var c = func (i int) { inClosuresScope += i } s := []int {1, 2, 3, 4, 5, 6} for _, value := range s { c(value); }
More about closures is available here.