I have an object named Gallery with several properties and methods. One of them, setCurrentPicture, removes all existing photos and videos DOM elements from gallery container b
I should add bind this to Array.prototype.forEach.call instead of implementing this to callback function.
Array.prototype.forEach.call(container.children, function(item) {
if (item.tagName === 'VIDEO') {
document.removeEventListener('click', this.togglePlayVideo);
}
if (item.tagName === 'VIDEO' || item.tagName === 'IMG') {
container.removeChild(item);
}
}.bind(this));
Thanks to all for the answers.