jeudi 4 mars 2021

Class and parameters with "if"? [closed]

So i have create a class and its extension. Can i use if to create some rules about classes. F.e. i create class:

class Apple {
    constructor(name, color, sweetness) {
        this.name = name;
        this.color = color;
        this.sweetness = sweetness;
    }
}

class Fruit extends Apple{
    cunstructor(name, color, sweetness, goodForCider, goodForJuice) {
        super(name, color, sweetness);
        this.goodForCider = goodForCider;
        this.goodForJuice = goodForJuice;
    }
}

Now can i set rules with if like

if ( name = '') {
  name = 'Unknown Fruit'
}

Can you use if this way in class? Thank for all you answers.

Aucun commentaire:

Enregistrer un commentaire