I have a class that copy objects and it looks like this:
Class CoppyComponent {
constructor(element) {
return Object.assgin(Object.create(Object.getPrototypeOf(element)), element);
}
}
I have another class to create HTML elements that use an array to keep track of the HTML elements created
Class Component {
constructor(){
this.arr = [];
}
}
I use the classes this way:
const hi = new Component();
hi.CreateEl({ type: "h1", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h2", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h3", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h4", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h6", text: "Hello", parrent: ".a" });
const h1Copy = new CoppyComponent(hi);
`h1Copy.load(".b");`
createEl methid just create a new HTML element
load method just modify the parent element HTML elements go into div with class b only instead of both divs (a, b)
I console.log both objects (hi, h1Copy) and are identical What I think the problem is but I am not sure is that both objects share the same array.