-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#36-Closures.dart
More file actions
28 lines (23 loc) · 811 Bytes
/
#36-Closures.dart
File metadata and controls
28 lines (23 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void main(){
//closure in Dart
//it is a special function that has access to the parent scope,even after the scope is close. example -->
String message = " this is normal message";
Function showMessage = (){
message = "this is a modified Message";
print(message);
};
//here we have access to parent varriable and we can modify it this is called closure.
showMessage();
//Defination:2 - A function object that has access to varriables in its lexicals scope.
//even when the function is used outside of its orginal scope. -->
Function talk = (){
String msg = "hi";
Function say = (){
msg = "Hello";//we modify the varriable
print(msg);
};
return say;
};
var m = talk(); //it is used perfectly in the outside of a function.
m();
}