Lexical closures

 /// What is Closure ?

/// Ans: A Closure is function object that has access to variables in its lexical scope,
/// even when the function is used outside of its original scope

/// Example of Lexical Closure
// void main() {
// var a = 0;
// print("Main function = $a");
//
// void outer() { // This is Lexical scope
// a = 5;
// print("Outer function = $a");
// }
//
// outer();
// }

/// Another Example of Lexical Closure
var a = 0;

void main() {
print("Main Function : $a");

void outer() {
a = 5;
print("Outer Function : $a");
}
outer();
demo();
}
void demo() {
a = 20;
print("Demo Function : $a");
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter