Здравствуйте
Есть класс
class Blocks {
constructor(container, array) {
this.container = container;
this.blocks = array;
this.renderBlock(array);
this.renderBlockMore();
}
addBlock(param1, param2, param3) {
const { blockElem } = new Block(param1, param2, param3);
this.container.appendChild(blockElem);
}
renderBlock(array) {
array.slice(0, 2).forEach(block => {
this.addCards(
block.param1,
block.param2,
block.param3
);
});
}
checkBlock(arr, n) {
const items = arr.filter(item => !n.includes(item));
const bItems = items.slice(0, 2);
return bItems;
}
renderBlockMore() {
const blocks = this.blocks;
const addBlocks = this.blocks.slice(0, 2);
console.log(addBlocks);
btnMore.addEventListener('click', () => {
if (addBlocks.length !== blocks.length) {
const newBlocks = this.checkBlock(blocks, addBlocks);
this.renderBlock(newBlocks);
newBlocks.forEach(item => addBlocks.push(item));
this.checkBlock(blocks, addBlocks);
if (addBlocks.length === blocks.length) {
btnMore.classList.add('show');
}
}
})
}
}
Получаю ошибку -
Cannot read property 'slice' of undefined.
Ошибку показывает в данном месте -
array.slice(0, 2).forEach(block => {
Подскажите, из-за чего так происходит, и как правильно связать методы
renderBlock
и
renderBlockMore
?