Знаю, что криво, но суть вы уловили.
const summ = {
element: document.getElementById("summ"),
clones: [],
getValue() {
return this.element.textContent;
},
renderClones(selector) {
if (this.clones.length > 0) {
this.clones.forEach((clone) => {
selector.append(clone);
});
}
},
createClone() {
const clone = document.createElement("div");
clone.classList.add(".new-clone");
clone.textContent = this.getValue();
this.clones.push(clone);
this.renderClones(document.body);
},
update(value) {
this.element.textContent = value;
if (this.clones.length > 0) {
this.clones.forEach((clone) => {
clone.textContent = value;
});
}
}
};
summ.createClone();
summ.createClone();
summ.element.addEventListener("click", () => {
summ.update(3000);
});