๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์๋ ๋ ๊ฐ์ง๊ฐ ์๋ค.
- ๊ฐ์ฒด ๋ฆฌํฐ๋ด
- ์์ฑ์ ํจ์
๋จ ํ๋์ ๊ฐ์ฒด๋ง์ ์์ฑํ ๋๋ ์ง๊ด์ ์ด๊ณ ๊ฐํธํ ๊ฐ์ฒด ๋ฆฌํฐ๋ด์ ์ฌ์ฉํ๊ณ ,
๊ฐ์ ๊ฐ์ฒด๋ฅผ ๋๋์์ฐํ ๋๋ ์์ฑ์ํจ์๋ฅผ ์ฌ์ฉํ๋ค.
๊ฐ์ฒด ๋ฆฌํฐ๋ด
const goodCoder = {
name : 'Noran',
age : 20,
}
* ์์ /์ ์ง๋ณด์๊ฐ ์ฉ์ดํ๋๋ก ๋ง์ง๋ง ๊ฐ์๋ ๋๋๋ก ,๋ฅผ ๋ถ์ฌ์ฃผ์.
๊ฐ์ฒด.์ ๊ทผ
goodCoder.name
goodCoder['age']
๊ฐ์ฒด.์ถ๊ฐ
goodCoder.gender = "Female";
goodCoder.clothes = "sweatshirt";
๊ฐ์ฒด.์ญ์
delete goodCoder.clothes;
์์ฑ์ ํจ์ (object constructor function)
function Coder(name, age, coding) {
this.name = name;
this.age = age;
this.coding = coding;
}
*์์ฑ์ ํจ์์ ์ฒซ ๊ธ์๋ ์์ฑ์์์ ๋ํ๋ด๊ธฐ ์ํด ๋๋ฌธ์๋ก ์์ฑํ๋ค. (ํ์ค์นผ ํ๊ธฐ๋ฒ)
ํ๋กํ ํ์ ์์ฑ
let coder1 = new Coder("Noran",10,"html");
let coder2 = new Coder("Paran",20,"css");
let coder3 = new Coder("Chorok",30,"js");
//coder1
Coder {name: "Noran", age : 10, coding : "html"}
//coder2
Coder {name: "Paran", age : 20, coding : "css"}
//coder3
Coder {name: "Chorok", age : 30, coding : "js"}
new ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํด์ ๊ฐ์ฒด ํ๋กํ ํ์ ์ ์์ฑํ ์ ์๋ค.
์ถ์ฒ : ์ฝ๋ฉ์๋ง https://www.youtube.com/@codingangma