[Dart] Dart scope & Closures
페이지 정보
작성자 sbLAB 댓글 0건 조회 984회 작성일 23-05-28 21:40본문
Dart scope & Closures
//Dart is a lexically scoped language
//sample1 for scope
var numberOne = 1;
void levelOne() {
var numberOne = 2;
print(numberOne);
}
//sample2 for scope & Closures
Function talk = () {
String msg = "Hi";
print("--start--");
Function say = () {
msg = msg+"-"+"Hello";
print(msg);
};
return say;
};
main() {
//sample1 for scope--------------------------------------
levelOne();
int i = 999;
for (var i = 0; i < 10; i++) {
print(i);
}
print('i in global scope : ${i}'); //i in global scope : 999
for (i = 0; i < 10; i++) {
print(i);
}
print('i in global scope : ${i}'); //i in global scope : 10
//sample2 for scope & Closures----------------------------
var speak = talk();
speak(); //Hi-Hell
speak(); //Hi-Hello-Hello
speak(); //Hi-Hello-Hello-Hello
}
[Result]
2
0
1
2
3
4
5
6
7
8
9
i in global scope : 999
0
1
2
3
4
5
6
7
8
9
i in global scope : 10
--start--
Hi-Hello
Hi-Hello-Hello
Hi-Hello-Hello-Hello
Dart Lexical Closures Tutorial (Functional Programming)
클로저(closure)의 개념(js)
https://poiemaweb.com/js-closure
댓글목록
등록된 댓글이 없습니다.