Last active
October 29, 2021 03:34
-
-
Save dened/3385fd713c1fffcd23057db44b9545c9 to your computer and use it in GitHub Desktop.
Замыкание
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// https://gist.github.com/dened/3385fd713c1fffcd23057db44b9545c9 | |
/// https://dartpad.dev/3385fd713c1fffcd23057db44b9545c9 | |
typedef Inc = int Function(); | |
Inc intrementer() { | |
var i = 0; | |
return () { | |
i++; | |
return i; | |
}; | |
} | |
void main() { | |
final increment = intrementer(); | |
print('hello ${increment()}'); | |
print('hello ${increment()}'); | |
print('hello ${increment()}'); | |
print('hello ${increment()}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment