[Dart] Dart scope & Closures > Flutter/Dart/Node

본문 바로가기
사이트 내 전체검색

Flutter/Dart/Node

[Dart] Dart scope & Closures

페이지 정보

작성자 sbLAB 댓글 0건 조회 1,600회 작성일 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) 

https://youtu.be/NaxyY2Rq0j8 


클로저(closure)의 개념(js) 

https://poiemaweb.com/js-closure 


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
287
어제
407
최대
1,279
전체
212,057

그누보드5
Copyright © sebom.com All rights reserved.