const print = console.log;
let animal = {
arr: [1, 2, 3],
};
function Rabbit(name) {
this.name = name;
}
Rabbit.prototype = animal;
let rabbit = new Rabbit("rabbit1");
let rabbit2 = new Rabbit("rabbi2");
print(rabbit.arr);
print(rabbit2.arr);
rabbit.arr.push(4);
print(rabbit.arr);
print(rabbit2.arr);
>[ 1, 2, 3 ]
>[ 1, 2, 3 ]
>[ 1, 2, 3, 4 ]
>[ 1, 2, 3, 4 ]
I'm new to javascript but i know that arr is a reference right so it sets the prototype to a reference to the animal object that holds the reference to the array, so how do you solve this?