본문 바로가기
js

class - food class 만들기

by 멋진 개구리 2021. 4. 22.
반응형

class

₩₩₩javascript

class Food{
    constructor(name){
        this.name = name;
        this.brands=[];
    }

addBrands(brand){
    this.brands.push(brand)
}
print(){
    console.log(`${this.name}을/를 파는 음식점들`)
    console.log(this.brands.join(`, `));
    }
}

const pizza = new Food('피자');
pizza.addBrand('피자헛');
pazza.addBrand('도미노 피자');

const chiken = new Food('피자');
chicken.addBrand('굽네치킨');
chicken.addBrand('BBQ');

₩₩₩

//

반응형

'js' 카테고리의 다른 글

비동기처리  (0) 2021.04.23
Truthy and Falsy  (0) 2021.04.23
async - await  (0) 2021.04.08
promise  (0) 2021.04.07
클릭한 버튼의 id값 확인  (0) 2021.03.25

댓글