[JavaScript] ์๋ฐ์คํฌ๋ฆฝํธ์์ Reflection ์ฌ์ฉํ๊ธฐ
...
2021. 9. 13. 15:06
์๋ฐ์์ ๋ณ์๋ช ์ผ๋ก ํด๋์ค๋ฅผ ์ธ์คํด์คํ ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฐฉ๋ฒ 1-์ธ์๋ ์๊ณ ์์ฑ์๋ง ์๋ ํด๋์ค์๋ง ํด๋น ํด๋์ค์ ์ธ์๊ฐ์๋ ์์ฑ์๊ฐ์๋ ๊ฒฝ์ฐ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ Class๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ด ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ธ์คํด์ค๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค. Class domainClass = Class.forName("com.femarket.domain." + domainName); Object domain = domainClass.newInstance(); ๋ฐฉ๋ฒ 2 ํด๋์ค์ ์ธ์๊ฐ์๋ ์์ฑ์๊ฐ์๋ ๊ฒฝ์ฐ์๋ ์๋ํ๋ ๋ ์์ ํ ๋ฐฉ๋ฒ์ ํด๋์ค ๊ฐ์ฒด๋ฅผ ์ฟผ๋ฆฌํ์ฌ ํด๋น Constructor๊ฐ์ฒด ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ด ๊ฐ์ฒด์ ๋ํ newInstance()๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๊ฒ์ ๋๋ค. Class clazz = Class.forName("..