Witam
Jak przebić ten kod aby za każdym razem po kliknięciu nie nadpisywał tablicy i nie tworzył nowej lecz push'ował do istniejącej?
class Book {
constructor(title, author){
this.title = title;
this.author = author;
this.data = [];
}
}
Book.prototype.addData = function(title, author) {
let obj = {title, author};
this.data.push(obj);
console.log(this.data);
}
button.addEventListener('submit', function(e) {
e.preventDefault();
const title = document.getElementById('title').value;
const author = document.getElementById('author').value;
const book = new Book(title, author);
book.addData(title, author);
});