I am new in OOP in Javascript, I wanted to have my Slider object with its own attributes and methods. It works fine until I add the Eventlistener with my method slideNextImage. Once this method is triggered every attribute inside the method is undefined. If I launch the method without attaching any event it works good.
function Slider(photos, currentPhoto){ //Constructor
this.photos = photos;
this.currentPhoto = currentPhoto;
}
Slider.prototype.slideNextImage = function () {
document.getElementById("slider").style.backgroundImage = "url(" + this.photos[this.currentPhoto] + ")";
console.log("La foto actual es la " + this.currentPhoto + " y en el almacen hay " + this.photos.length);
}
var photos = ["../imagenes/images/wallpaper_5.jpg", "../imagenes/images/wallpaper_4.jpg", "../imagenes/images/wallpaper_3.jpg", "../imagenes/images/wallpaper_2.jpg", "../imagenes/images/wallpaper_1.jpg"];
var slider = new Slider(photos, 0);
document.getElementById("next").addEventListener("click", slider.slideNextImage);
Thank you in advance.