sdf

← разместить еще код

Расшаренный код:

class Iteration {

    constructor() {
        this.iteration();
        this.eventIter;
    }
    iteration() {
        console.log('f');

        var buttonsPlus = document.querySelectorAll('.iteration__button-plus');
        var buttonsMin = document.querySelectorAll('.iteration__button-min');
        let parent =buttonsMin[0].parentNode.parentNode;
        console.log(parent);
        this.eventIter = new EventIter(parent);
        console.log(this.eventIter.plus);
        buttonsPlus.forEach(element => {
            element.addEventListener("click", this.eventIter.plus);
        });
        buttonsMin.forEach(element => {
            element.addEventListener("click", this.eventIter.min);
        });
    }
}

class EventIter {
    constructor(parentContainer) {
        this.parentContainer = parentContainer;
        this.eventIterationChange = new CustomEvent('iterationChange');// создаём событие
    }

    plus() {
        let content = this.previousSibling.previousSibling;
        let text = String(parseInt(content.innerText) + 1);
        content.innerText = text;
        console.log(this.parentContainer);
        this.parentContainer.dispatchEvent(eventIterationChange); // вызываем событие
        if (text !== '0') {
            content.previousSibling.previousSibling.disabled = false;
        }
    }


    min() {
        let content = this.nextSibling.nextSibling;
        let text = String(parseInt(content.innerText) - 1);
        content.innerText = text;
        this.parentContainer.dispatchEvent(eventIterationChange);// вызываем событие
        if (text === '0') {
            this.disabled = true;
        }
    }
}



let i=new Iteration();