I have a class Playlist :
function Playlist() {
this.episodes = [ /*episode list*/ ];
};
and I want to make a method displaying each episode :
Playlist.prototype.display = function() {
$('.episodeList').each(function(index) {
$(this).children('title').text(this.episodes[index].title);
});
}
The problem is that the ‘this’ at the end, before ‘.episodes[index]’ represent the dom object selected and not my playlist.
How can I solve this problem ? Thanks.
A common practice in Javascript is to make a new variable for storing the current class, since the content of the
thisvariable changes with context. Consider something likefor your Playlist class definition, and call myPlaylist.display()
to display the content.