프로토타입

김혁중·2022년 3월 1일
0

JavaScript

목록 보기
3/23

1️⃣ 프로토타입

  • prototype
  • 따로 생성하지 않아도, 자동으로 존재하는 유전자
  • 프로토타입에 추가하면, 자식들이 사용가능
class Skill {
  constructor() {
    this.q = 'strike'
    this.w = 'snowball'
  }
}

Skill.prototype.price = '1350RP'
let nunu = new Skill()

console.log(nunu) // Skill { q: 'strike', w: 'snowball' }
console.log(nunu.price) // '1350RP'

2️⃣ 관계

3️⃣ prototype

  • 부모에 있는 유전자 검사

3️⃣ proto

  • 자식에 있는 유전자 검사
Skill.prototype === nunu.__proto__
Skill.prototype.constructor === Skill
profile
Digital Artist가 되고 싶은 초보 개발자

0개의 댓글