// Person => instances document.addEventListener('DOMContentLoaded', () => { const $form = document.querySelector('form'); const $modal = document.querySelector('.modal-mask'); const $btnShow = document.querySelector('.btn-show'); const $btnClose = document.querySelector('.btn-close'); const persons = []; class Person { constructor(firstName, surName, age, job) { this.firstName = firstName; this.surName = surName; this.age = age; this.job = job; } addPerson() { persons.push(this); } } $form.addEventListener('submit', (e) => { e.preventDefault(); const _this = e.target, firstName = _this.name.value, surName = _this.surname.value, age = _this.age.value, job = _this.job.value; new Person(firstName, surName, age, job).addPerson(); }); const showPersons = function () { $modal.style.display = 'flex'; document.body.style.overflow = 'hidden'; const list = $modal.querySelector('tbody'); if (persons.length) { list.innerHTML = ''; for (let item of persons) { list.innerHTML += `
${item.firstName}
${item.surName}
${item.age}
${item.job}