-
실행컨텍스트Front-end/Javascript 2021. 3. 27. 11:02
실행 컨텍스트 (Execution Context)
실행할 코드에 제공할 환경정보(식별자와 스코프) 를 모아놓은 객체이며, 콜스택에 쌓아올린 후 가장 위에 있는 컨텍스트와 관려있는 코드를 실행합니다.
실행컨텍스트의 종류 :
1. Global Execution Context
2. Functional Execution Context
3. Eval Context
ES6명세에서는 실행 컨텍스트에 담기는 정보를 아래와 같이 정의합니다.
- Execution contexts contain the current evaluation state of code, a reference to the code (function) itself, and possibly references to the current lexical environments.
Execution contexts are managed in a stack. - Lexical environments contain an environment record in which the variables are stored, and a reference to their parent environment (if any).
Lexical environments build a tree structure.
Variable Environment
현재 컨텍스트에 정의된 변수들과 함수들에 대한 정보이며 Lexical Environment 의 한 유형일 뿐이다.
Lexical Environment
변수를 선언하면 Lexical Environment에 올라간다. 어휘적 환경, 정적인 환경 (lexical environment를 자바스크립트에서 구현한 대상)
ㄴ 컨텍스트를 구성하는 환경 정보
VariableEnvironment와 LexicalEnviroment의 내부는 현재 컨텍스트와 관련된 코드의 식별자 정보들이 저장되는 environmentRecord와 스코프 체인을 위해 존재하는 참조인 outer ( EnvironmentReference ) 로 구성되어있다.
environmentRecord
현재 컨텍스트와 관련된 코드의 식별자 정보들이 저장된다. 컨텍스트를 구성하는 함수에 지정된 매개변수 식별자, 선언자 함수가 있을 경우 그 함수 자체, var로 선언된 변수의 식별자 등이 environmentRecord에 해당한다.
* 호이스팅 : 변수 정보를 끌어올리는 개념 (자바스크립트 엔진이 실제로 끌어올리지는 않는다)
'Front-end > Javascript' 카테고리의 다른 글
프로토타입 (0) 2021.03.30 자바스크립트의 호출스택,큐 그리고 이벤트루프 (0) 2021.03.28 클로저(Closure) (0) 2021.03.23 this 바인딩 (0) 2021.03.23 자바스크립트 객체의 깊은 복사 (0) 2020.05.11 - Execution contexts contain the current evaluation state of code, a reference to the code (function) itself, and possibly references to the current lexical environments.