Preface
๐ ๊ฐ๋ฐ ๊ณต๋ถ 6๊ฐ์ ์ฐจ์ธ to-be ๊ฐ๋ฐ์์ ์์ต blog๐๏พ Feb 20 ~ 26, 2022
Execution Context
: code๋ฅผ ์คํํ๋ ๋ฐ์ ํ์ํ ํ๊ฒฝ์ ์ ๊ณตํ๋ ๊ฐ์ฒด
*ํ๊ฒฝ : code ์คํ์ ์ํฅ์ ์ฃผ๋ ์กฐ๊ฑด์ด๋ ์ํ
Keywords
- scope chain = execution context chain
- Global Execution Conte xt : Global Object (GO)
- this object
- window object
- Function Execution Context = Activation Object (AO)
Eval Execution Context
- Global Object (GO)
- built in ๊ฐ์ฒด (Math, String etc.)
- BOM
- DOM
- ์ ์ญ ๋ณ์
- Activation Object (AO)
- ํจ์ ์ ์ธ
- ๋งค๊ฐ ๋ณ์
- ๋ณ์
- lexical environment
= lexical scope
= ์ ์ ํ๊ฒฝ
= environment record + outer environment reference
- environment record : ์๋ณ์์ ์๋ณ์์ binding๋ ๊ฐ์ ๊ธฐ๋กํด๋๋ ๊ฐ์ฒด
์ฒ์์ JavaScript engine์ด ์ ์ฒด code๋ฅผ scanํ๋ฉด์ ๋ณ์๊ฐ์ ์ ๋ณด๋ฅผ ๋ฏธ๋ฆฌ ๊ธฐ๋กํด๋๋ ๊ณณ
- outer environment reference : ๋ฐ๊นฅ lexical environment๋ฅผ ๊ฐ๋ฆฌํด
STEP 1. Creation Phrase
: Execution Context ์์ฑ
ย ย ์ ์ธ๋ฌธ๋ง ์คํํด์ environment record์ ๊ธฐ๋ก
- GO, AO, this ํ์ฑ
- environment record
- ๋ณ์ hoisting
var
๋ ์ ์ธ๊ณผ ์ด๊ธฐํ๋ฅผ ๋ชจ๋ ํด ํ ๋น๋ฌธ ์ ์๋ 'undefined'๋ผ๋ ๊ฐ์ ์ฝ์ง๋ง,
let
๊ณผ const
๋ ์ ์ธ๋ง ํ๊ธฐ ๋๋ฌธ์ ํ ๋น๋ฌธ ์ ๊น์ง ๋ณ์์ ์๋ฌด๋ฐ ๊ฐ์ด ๋ด๊ธฐ์ง ์์ ์ ํจํ ๊ฐ์ ์ฝ์ด์ฌ ์ ์์ ("์ ์ธ ์ ์๋ ๋ณ์๋ฅผ ์ฐธ์กฐํ ์ ์์"์์ '์ ์ธ ์ ' ์์ญ = Temporal Dead Zone)
โป declaration : memory ๊ณต๊ฐ์ ํ๋ณดํ๊ณ memory ์ฃผ์๋ฅผ ์๋ณ์์ ์ฐ๊ฒฐ
โป initialization : ์๋ณ์์ ์๋ฌต์ ์ผ๋ก undefined ๊ฐ์ bindingํ์ฌ ์ด๊ธฐํ
- ํจ์ hoisting
- ํจ์ ํํ์์ ๋ณ์ hoisting๊ณผ ๋์ผํ๊ฒ ๋์ (ํ์ดํํจ์)
- ํจ์ ์ ์ธ๋ฌธ์ ์ ์ธ๊ณผ ๋์์ ํจ์๊ฐ ์์ฑ๋์ด ์ ์ธ ์ ์๋ ํจ์๋ฅผ ์ฌ์ฉํ ์ ์์ (function ํจ์)
- outer environment reference
- ์๋ณ์ ๊ฒฐ์ : code์์ ๋ณ์๋ ํจ์์ ๊ฐ์ ๊ฒฐ์ ํ๋ ๊ฒ
- ๋ณ์ shadowing : ๋์ผํ ์๋ณ์๋ก ์ธํด ์์ (outer) scope์์ ์ ์ธ๋ ์๋ณ์์ ๊ฐ์ด ๊ฐ๋ ค์ง๋ ํ์
- scope chain : ์๋ณ์๋ฅผ ๊ฒฐ์ ํ ๋ ํ์ฉํ๋ scope๋ค์ ์ฐ๊ฒฐ list
STEP 2. Execution Phrase
: ์ ์ธ๋ฌธ ์ธ ๋๋จธ์ง code๋ฅผ ์์ฐจ์ ์ผ๋ก ์คํ
ย ย ํ์ ์ environment record๋ฅผ ์ฐธ์กฐํ๊ฑฐ๋ update
- GO, AO, this
- ๊ฐ ํ ๋น
- this๋ ํจ์ ํธ์ถ pattern ๋๋ lexical scope์ ๋ฐ๋ผ ๊ฐ์ด ์ ํด์ง
Endnote
๐ the source of this content
ํฐ๋์ํฐ์ - ์คํ์ปจํ
์คํธ
์ฐ์ํTech - [10๋ถ ํ
์ฝํก] ๐ ํ๋ฃจ์ ์คํ ์ปจํ
์คํธ