This is my JavaScript class:
class Animal{
constructor(name, sound){
this.name = name;
this.sound = sound;
}
speak(){
console.log(this.name + `${this.sound}`);
}
}
I want to execute some code when first instance of Animal is created. I mean:
let dog1 = new Animal('n1', 's1'); //first instance - run my code
let dog2 = new Animal('n2', 'n2');// second instance - do nothing
Is it possible to do? Of course without changing Animal class in code above. Only using its constructor.