studyHard
article thumbnail
Published 2023. 3. 16. 23:57
beesbeesbees SEB_FE_44/반딧불 ✨

 

 

 

공통된 특성을 기반으로 클래스, 상속으로 과제를 완수하기✨✨

 

class Grub {
  constructor() {
    this.age = 0;
    this.color = "pink";
    this.food = "jelly";
  }
  eat() {
    return "Mmmmmmmmm jelly";
  }
}

class Bee extends Grub {
  constructor() {
    super();
    this.age = 5;
    this.color = "yellow";
    this.job = "Keep on growing";
  }
}

class HoneyMakerBee extends Bee {
  constructor() {
    super();
    this.age = 10;
    this.job = "make honey";
    this.honeyPot = 0;
  }

  makeHoney() {
    this.honeyPot += 1;
  }
  giveHoney() {
    this.honeyPot -= 1;
  }
}

class ForagerBee extends Bee {
  constructor() {
    super();
    this.age = 10;
    this.job = "find pollen";
    this.canFly = true;
    this.treasureChest = [];
  }
  forage(보물) {
    this.treasureChest.push(보물);
  }
}

 

 

오늘 예비군을 갔다 오느라 반딧불반에 당첨되었다🫠 (공부할 시간이 없다..)

문제를 풀면서 extends, super에 대해 알게 됐다.

 

메서드를 작성할 때 프로토타입을 적었다가 바꿔줬는데 뭐가 다른 건지 모르겠다.

따로 복제를 안 하기 때문에 constructor(), super()는 비워뒀는데 이것도 맞는지 모르겠다.

 

어질어질하다

'SEB_FE_44 > 반딧불 ✨' 카테고리의 다른 글

AJAX  (0) 2023.03.30
React-Twittler-State-Props  (0) 2023.03.27
fetch API  (0) 2023.03.21
JavaScript Koans  (1) 2023.03.06
2023.02.13 ~ 0.3.0.4 까지의 정리  (0) 2023.03.05
profile

studyHard

@언젠간코딩잘함

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!