๐JS/โกver.0
section29-ํ๋กํ ํ์ , ํด๋์ค, ๊ทธ๋ฆฌ๊ณ OOP(๋ฐฑ์๋๋ฅผ ๋ฃ๊ณ ๋์ค์ ๋ค์ ๋ค์ด๋ ๋ฌด๋ฐฉํ๋ค)
4:Bee
2023. 4. 4. 22:49
728x90
| Topic | explain | class | |
| Prototype | prototype/__proto__ | ํ๋กํ ํ์ ์ ์ฒญ์ฌ์ง๊ณผ ๊ฐ๋ค. ์๋ฅผ ๋ค์ด arr.includes(2)๋ฅผ ์ฌ์ฉํ ๋ includes()์ ํจ์๋ ํ๋กํ ํ์ ๊ฐ์ฒด์์ ์ ์๋๋ค. | ํ๋กํ ํ์ ์ด๋? |
|
String.prototype.yell = function () {
return `OMG!! ${this.toUpperCase()}!!!!`
}
Array.prototype.pop = function() {
return 'SORRY I WANT THAT ELEMENT, I WILL NEVER POP IT OFF!';
}
|
|||
| ์ฌ๊ธฐ์ prototpye์ ๋ฉ์๋๋ ํน์ฑ์ ์ถ๊ฐํ๋ ์ค์ ๊ฐ์ฒด์ด๋ค. ํ ํ๋ฆฟ ๊ฐ์ฒด, ์ฆ ํ๋กํ ํ์ ์ด๋ค. | |||
![]() ![]() |
|||
| ์ฌ๊ธฐ์ [[prototpye]]/(__proto__)์ ์ฐธ์กฐ์ด๋ค. [[prototpye]]/(__proto__)์ ์ด ๋ฐฐ์ด์ด๋ ๋ฌธ์์ด์ ํน์ฑ ์ด๋ฆ์ด๋ค. | |||
| OOP์ ๊ฐ์ | - | ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ ๊ฐ์ | |
| ํฉํ ๋ฆฌํจ์ | ํฉํ ๋ฆฌ๋ผ๋ ์ฉ์ด๋ ์ด๋ค ๊ฐ์ ์ ๋ฌํ๋ฉด ์ด ํฉํ ๋ฆฌ๊ฐ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ฃผ๊ณ ๋ง์ง๋ง์ ๋ฐํํ์ฌ ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ ์ ์๊ฒ ๋๋ค๋ ๊ฒ์ด๋ค. | ||
| ์ดํด๊ฐ ์์๊ฐ๋ค. ๋ค์ ๋ค์ด๋ณด๊ณ ๋ค์ ๋ณด๊ธฐ |
function makeColor(r,g,b){
const color = {};
color.r = r;
color.g = g;
color.b = b;
return color;
}
|
||
![]() |
ํฉํ ๋ฆฌ ํจ์ | ||
| - | ์์ฑ์ ํจ์ | ||
| ํด๋์ค | JavaScriptํด๋์ค | ||
|
class Color {
constructor(r, g, b, name) {
this.r = r;
this.g = g;
this.b = b;
this.name = name;
// console.log("constructor");
// console.log(r, g, b);
}
greet() {
return `Hello From A Color!! ${this.name}`
}
}
const c1 = new Color(32, 56, 78, 'idk');
|
|||
728x90


