728x90
๋ฐ์ํ
ํจ์์ ์ ํ : ํจ์์ ๋งค๊ฐ๋ณ์๋ฅผ ์ด์ฉํ ํํ
function func(num, str1, str2) {
document.write(num + str1 + str2 + "๋์์ต๋๋ค.");
}
func("1", "ํจ์", "์คํ");
func("2", "์๋ฐ์คํฌ๋ฆฝํธ", "์คํ");
func("3", "์ ์ด์ฟผ๋ฆฌ", "์คํ");
๊ฒฐ๊ณผ ๋ณด๊ธฐ
ํจ์ ์ ํ : ํจ์์ ๋ณ์๋ฅผ ์ด์ฉํ ํํ
function func(num, str1, str2) {
document.write(num + ". " + str1 + "๊ฐ " + str2 + "๋์์ต๋๋ค.
");
}
const youNum1 = 1;
const youNum2 = 2;
const youNum3 = 3;
const youStr1 = "ํจ์";
const youStr2 = "์๋ฐ์คํฌ๋ฆฝํธ";
const youStr3 = "์ ์ด์ฟผ๋ฆฌ";
const youCom = "์คํ";
func(youNum1, youStr1, youCom);
func(youNum2, youStr2, youCom);
func(youNum3, youStr3, youCom);
// 1. ํจ์๊ฐ์คํ๋์์ต๋๋ค.
// 2. ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ์คํ๋์์ต๋๋ค.
// 3. ์ ์ด์ฟผ๋ฆฌ๊ฐ์คํ๋์์ต๋๋ค.
๊ฒฐ๊ณผ ๋ณด๊ธฐ
ํจ์ ์ ํ : ํจ์์ ๋ฐฐ์ด, ๊ฐ์ฒด๋ฅผ ์ด์ฉํ ํํ
function func(num, str1, str2) {
document.write(num + ". " + str1 + "๊ฐ " + str2 + "๋์์ต๋๋ค.
");
}
const info = [
{
num: "1",
name: "ํจ์",
com: "์คํ"
},
{
num: "2",
name: "์๋ฐ์คํฌ๋ฆฝํธ",
com: "์คํ"
},
{
num: "3",
name: "์ ์ด์ฟผ๋ฆฌ",
com: "์คํ"
}
];
func(info[0].num, info[0].name, info[0].com);
func(info[1].num, info[1].name, info[1].com);
func(info[2].num, info[2].name, info[2].com);
๊ฒฐ๊ณผ ๋ณด๊ธฐ
ํจ์ ์ ํ : ๊ฐ์ฒด ์์ ๋ณ์์ ํจ์๋ฅผ ์ด์ฉํ ํํ
const info = {
num1: 1,
name1: "ํจ์",
word1: "์คํ",
num2: 2,
name2: "์๋ฐ์คํฌ๋ฆฝํธ",
word2: "์คํ",
num3: 3,
name3: "์ ์ด์ฟผ๋ฆฌ",
word3: "์คํ",
result1: function () {
document.write(info.num1 + ". " + info.name1 + "๊ฐ " + info.word1 + "๋์์ต๋๋ค.
");
},
result2: function () {
document.write(info.num2 + ". " + info.name2 + "๊ฐ " + info.word2 + "๋์์ต๋๋ค.
");
},
result3: function () {
document.write(info.num3 + ". " + info.name3 + "๊ฐ " + info.word3 + "๋์์ต๋๋ค.
");
}
}
info.result1();
info.result2();
info.result3();
๊ฒฐ๊ณผ ๋ณด๊ธฐ
ํจ์ ์ ํ : ๊ฐ์ฒด ์์ฑ์ ํจ์
function func(num, name, word) {
this.num = num;
this.name = name;
this.word = word;
this.result = function () {
document.write(this.num + ". " + this.name + "๊ฐ " + this.word + "๋์์ต๋๋ค.
");
}
}
//์ธ์คํด์ค ์์ฑ
const info1 = new func("1", "ํจ์", "์คํ");
const info2 = new func("2", "์๋ฐ์คํฌ๋ฆฝํธ", "์คํ");
const info3 = new func("3", "์ ์ด์ฟผ๋ฆฌ", "์คํ");
//์คํ
info1.result();
info2.result();
info3.result();
info.result3();
๊ฒฐ๊ณผ ๋ณด๊ธฐ
ํจ์ ์ ํ : ํ๋กํ ํ์ ํจ์
function func(num, name, word){
this.num = num;
this.name = name;
this.word = word;
}
func.prototype.result = function(){
document.write(this.num + ". " + this.name + "๊ฐ " + this.word + "๋์์ต๋๋ค.");
} //ํจ์๋ฅผ ๋นผ๋ฉด ์คํํ๊ณ ์ถ์๊ฒ๋ง ์คํ ๊ฐ๋ฅ. ๋ฐ์ผ๋ก ๋บ๊ฑฐ๋ ๋ฉ๋ชจ๋ฆฌ ์๋ผ๊ธฐ ์ํด ์ํ๋ ๊ฒ๋ง, ํจ์ ๋ง์์ง๋ฉด ์์ค ๋ณต์ก
//์ธ์คํด์ค ์์ฑ
const info1 = new func("1", "ํจ์", "์คํ");
const info2 = new func("2", "์๋ฐ์คํฌ๋ฆฝํธ", "์คํ");
const info3 = new func("3", "์ ์ด์ฟผ๋ฆฌ", "์คํ");
//์คํ
info1.result();
info2.result();
info3.result();
๊ฒฐ๊ณผ ๋ณด๊ธฐ
1. ํจ์๊ฐ ์คํ๋์์ต๋๋ค.
2. ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋์์ต๋๋ค.
3. ์ ์ด์ฟผ๋ฆฌ๊ฐ ์คํ๋์์ต๋๋ค.
ํจ์ ์ ํ : ๊ฐ์ฒด ๋ฆฌํฐ๋ด ํจ์
function func(num, name, word) {
this.num = num;
this.name = name;
this.word = word;
}
func.prototype = {
result1: function () {
document.write(this.num + ". " + this.name + "๊ฐ " + this.word + "๋์์ต๋๋ค.
");
},
result2: function () {
document.write(this.num + ". " + this.name + "๊ฐ " + this.word + "๋์์ต๋๋ค.
");
},
result3: function () {
document.write(this.num + ". " + this.name + "๊ฐ " + this.word + "๋์์ต๋๋ค.
");
}
}
//์ธ์คํด์ค ์์ฑ
const info1 = new func("1", "ํจ์", "์คํ");
const info2 = new func("2", "์๋ฐ์คํฌ๋ฆฝํธ", "์คํ");
const info3 = new func("3", "์ ์ด์ฟผ๋ฆฌ", "์คํ");
//์คํ
info1.result1();
info2.result2();
info3.result3();
๊ฒฐ๊ณผ ๋ณด๊ธฐ
1. ํจ์๊ฐ ์คํ๋์์ต๋๋ค.
2. ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ์คํ๋์์ต๋๋ค.
3. ์ ์ด์ฟผ๋ฆฌ๊ฐ ์คํ๋์์ต๋๋ค.
728x90
๋ฐ์ํ
'์๋ฐ์คํฌ๋ฆฝํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JQuery๋? (5) | 2022.08.30 |
---|---|
GSAP๋? (7) | 2022.08.29 |
charAt() (7) | 2022.08.22 |
match() (6) | 2022.08.22 |
search() (5) | 2022.08.22 |
๋๊ธ