-
[JS] μ€μ΅ - BeesbeesbeescodeStates front-end/Java Script 2023. 1. 16. 19:42λ°μν
π Beesbeesbees
π νμ΅ λͺ©ν
- ν΄λμ€μ μΈμ€ν΄μ€μ λν΄ μ΄ν΄νκ³ μλ€.
- νλ‘ν νμ μ΄ λ¬΄μμΈμ§ μκ³ κ°μ λΉκ΅ν μ μλ€.
- νλ‘ν νμ 체μΈμ νμ©ν μ μλ€.
πΆ λμ μ€μ΅
1) μ½λ© μ μ΅μμ ν΄λμ€κ° μ΄λμ§λ₯Ό νμΈ
2) λΆλͺ¨ - μμκ΄μ κ΄κ³λ₯Ό λͺ νν μ΄ν΄
3) μμ λͺ λ Ήμ΄ μ¬μ©
4) this, superμ μ΄ν΄
<Bee.js>
const Grub = require('./Grub'); class Bee extends Grub { // Grupμ μμ±μ μμ λ°λλ€ constructor() { super(); // μμ ν΄λμ€μ μμ±μλ₯Ό νΈμΆ this.age = 5; // Bee.ageμ μμ± μ μ this.job = 'Keep on growing'; // Bee.jobμ μμ± μ μ this.color = 'yellow'; // Bee.colorμ μμ± μ μ } } module.exports = Bee;
<grub.js>
class Grub { // κ°μ₯ λ¨Όμ ν΄λμ€λ₯Ό μ μνλ κ²μ΄ μ’λ€ constructor() { this.age = 0; // Grub.age μμ± μ μ this.color = 'pink'; // Grub.color μμ± μ μ this.food = 'jelly'; // Grub.food μμ± μ μ } eat() { // eat ν¨μ νΈμΆ return 'Mmmmmmmmm ' + this.food; // ν ν릿리ν°λ΄ μ¬μ©νμ¬ foodμμ±μ κ°μ Έμ μ μ } } module.exports = Grub;
<HoneyMakerBee.js>
const Bee = require('./Bee'); class HoneyMakerBee extends Bee { // Beeμ μμ±μ μμ λ°λλ€ constructor() { super(); // μμ ν΄λμ€μ μμ±μλ₯Ό νΈμΆ this.age = 10; // HoneyMakerBee.age μ μμ±μ μ μ this.job = 'make honey'; // HoneyMakerBee.job μ μμ±μ μ μ this.honeyPot = 0; // HoneyMakerBee.honeyPot μ μμ±μ μ μ } makeHoney() { //makeHoney ν¨μ νΈμΆ this.honeyPot++; // honeyPot`μ 1μ© μΆκ° } giveHoney() { //giveHoney ν¨μ νΈμΆ this.honeyPot--; //honeyPot`μ 1μ© κ°μ } } module.exports = HoneyMakerBee;
<ForagerBee.js>
const Bee = require('./Bee'); class ForagerBee extends Bee { // Beeμ μμ±μ μμ λ°λλ€ constructor() { super(); // μμ ν΄λμ€μ μμ±μλ₯Ό νΈμΆ this.age = 10; // ForagerBee.age μ μμ±μ μ μ this.canFly = true; // ForagerBee.canFly μ μμ±μ μ μ this.job = 'find pollen'; // ForagerBee.job μ μμ±μ μ μ this.treasureChest = []; // ForagerBee.treasureChest μ μμ±μ λΉ λ°°μ΄λ‘ μ μΈ } forage(treasure) { this.treasureChest.push(treasure); // `treasureChest` μμ±μ 보물μ μΆκ° } } module.exports = ForagerBee;
π§ thisλ₯Ό μ°λ μ΄μ
μλ°μμλ μΈμ€ν΄μ€ μμ μ κ°λ¦¬ν€λ ν€μλ
λ©€λ²λ³μμ μλ³μκ° κ²ΉμΉλ κ²½μ°κ° λ°μν λ μ μ©νκ² μ¬μ©!
μμΈν λ΄μ© πππππ(μ μ©νμ΅λλΉ)
https://smoothiecoding.kr/%EC%9E%90%EB%B0%94-this-%EC%9D%98%EB%AF%B8/
μλ° this μλ―Έ | μλ° μ λ¬Έκ°μ’ 13 - μ€λ¬΄λμ½λ©
μλ° this μλ―Έλ₯Ό νμ΅ν©λλ€. ν΄λμ€ μμμ this μ μ©λ²μ μ΄ν΄ν©λλ€.
smoothiecoding.kr
λ°μν'codeStates front-end > Java Script' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JS] chapter19. λΉλκΈ°1 - java script (0) 2023.01.17 [JS] μμλλ©΄ μΈλͺ¨μλ μ λΉν JSμ©μ΄μ¬μ (0) 2023.01.17 [JS] chapter18. ν¬λ‘ν νμ κ³Ό μ²΄μΈ (0) 2023.01.13 [JS] chapter17. νλ‘ν νμ κ³Ό ν΄λμ€ (0) 2023.01.13 [JS] chapter16. κ°μ²΄ μ§ν₯ - κ°μ²΄ μ§ν₯ νλ‘κ·Έλλ° (0) 2023.01.13