Proxy์ Reflect
Proxy์ Reflect
๐ Proxy Objects
Proxy
๊ฐ์ฒด๋ ๋ค๋ฅธ ๊ฐ์ฒด์ proxy๋ฅผ ๋ง๋๋๋ฐ, ๊ทธ ๊ฐ์ฒด์ ๊ธฐ์ด์ ์ธ operation์ ๊ฐ๋ก์ฑ์ ์ฌ์ ์ํ๋ค.
Description
constructor๋ก ํธ์ถ๋๋ฉด, Proxy exotic objecr๋ฅผ ์์ฑํ๊ณ ์ด๊ธฐํํ๋ค.
function์ผ๋ก์ ํธ์ถ๋๋๋ก ์๋๋์ง ์์๋ค. ๋ง์ฝ, proxy๋ฅผ ํจ์์ฒ๋ผ ํธ์ถํ๋ฉด exeption์ด ๋์ ธ์ง๋ค.
Proxy Constructor
[[Prototype]]
์ด ๋ด๋ถ์ ์ผ๋ก ์๊ณ , ๊ทธ ๊ฐ์Function.prototype
์ด๋ค.prototype
ํ๋กํผํฐ๋ฅผ ๊ฐ๊ณ ์์ง ์๋ค. Proxy exotic objects๊ฐ ์ด๊ธฐํํ๋๋ฐ ํ์ํ[[Prototype]]
์ ๋ด๋ถ์ ์ผ๋ก ๊ฐ๊ณ ์์ง ์๊ธฐ ๋๋ฌธ์ด๋ค.์ฐธ๊ณ :
[[Prototype]]
vs prototype ํ๋กํผํฐ[[Prototype]]
:__proto__
๊ฐ์ฒด๋ ์์ฑ์์ ํ๋กํ ํ์ ๊ฐ์ฒด๋ฅผ ๊ฐ๋ฆฌํจ๋ค.
ํจ์ ๊ฐ์ฒด๋ Function.prototype์ ๊ฐ๋ฆฌํจ๋ค.
prototype ํ๋กํผํฐ
ํจ์๊ฐ์ฒด๋ง ๊ฐ๊ณ ์๋ ํ๋กํผํฐ์ด๋ค.
ํ๋กํ ํ์ ๊ฐ์ฒด(Prototype Object)๋ฅผ ๊ฐ๋ฆฌํจ๋ค.
Proxy ( target, handler )
Proxy๋ ๋ ํ๋ผ๋ฏธํฐ๋ก ๋ง๋ค์ด์ง๋ค.
target : proxyํ๊ณ ์ถ์ ์๋์ ๊ฐ์ฒด
handler : ์ด๋ ํ operation์ ๊ฐ์ ธ์์, ์ด๋ป๊ฒ ์ฌ์ ์ํ ๊ฒ์ธ์ง๋ฅผ ์ ์ํ ๊ฐ์ฒด
handler.construct()
handler.construct()๋ฉ์๋๋ new
operator๋ฅผ ๊ฐ๋ก์ฑ๋ค.
handler.apply()
handler.apply()๋ ํจ์ ํธ์ถ์ ๊ฐ๋ก์ฑ๋ค.
์์
Proxy๋ฅผ ์ฌ์ฉํ ๋, this binding
์ด ๊น๋ค๋ก์ด ๋ถ๋ถ์ด๋ค. ์ด๋ ํ ๋ฉ์๋์ด๊ฑด this๊ฐ Proxy์ ๋ฐ์ธ๋ฉ ๋์ด, interceptํ ์ ์๊ธฐ๋ฅผ ๋ฐ๋๋ค. ES6์์ Reflect
๋ผ๋ ์๋ก์ด ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋์๊ณ , ์ด๊ฒ์ด ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด์ค๋ค.
๐ Reflect Object
Description
Reflect๋ ์ผ๋ฐ์ ์ธ ๊ฐ์ฒด์ด๋ค.
ํจ์ ๊ฐ์ฒด๊ฐ ์๋๋ค => constructible ํ์ง ์ใด๋ค.
Reflect ๋ด๋ถ์๋
[[Construct]]
method๊ฐ ๋ด๋ถ์ ์๋ค =>new
operator๋ฅผ ์ฌ์ฉํ์ฌ constructor๋ก ์ฌ์ฉํ ์ ์๋ค.Reflect๋
[[Call]]
internal method๊ฐ ์๋ค => ํจ์์ฒ๋ผ ํธ์ถ๋ ์ ์๋ค.๋ชจ๋ Reflect์ ๋ฉ์๋์ ํ๋กํผํฐ๋ staticํ๋ค.
์ถ์ฒ
Last updated