Dart Language Guide
  • Dart Language Guide (한국어)
  • LANGUAGE GUIDE
    • A basic Dart program
    • Important concepts
    • Keywords
    • Variables
    • Built-in types
      • Numbers
      • String
      • Booleans
      • Lists
      • Set
      • Maps
  • Functions
    • Parameters
    • The main() function
    • Functions as first-class objects
    • Anonymous functions
    • Lexical scope
    • Lexical closures
    • Testing functions for equality
    • Return values
    • Generators
Powered by GitBook
On this page
  1. Functions

Lexical scope

Dart는 어휘적으로 범위가 지정된 언어입니다. 이는 코드의 레이아웃만으로 변수의 범위가 정적으로 결정된다는 것을 의미합니다. 중괄호를 바깥쪽으로 따라가면 변수가 범위 내에 있는지 확인할 수 있습니다.

다음은 각 범위 수준에서 변수가 있는 중첩된 함수의 예입니다.

bool topLevel = true;

void main() {
  var insideMain = true;

  void myFunction() {
    var insideFunction = true;

    void nestedFunction() {
      var insideNestedFunction = true;

      assert(topLevel);
      assert(insideMain);
      assert(insideFunction);
      assert(insideNestedFunction);
    }
  }
}

중첩된 함수인 nestedFunction()이 최상위 수준까지 모든 수준의 변수를 사용할 수 있는 것에 주목하세요.

PreviousAnonymous functionsNextLexical closures

Last updated 2 years ago