I have several div with the same "album" class, so I wanted to create a class using constructor and prototype. Here's what I did
function Album(album){
this.album = album;
console.log(this.album === album)
console.log($(this.album) === $(album))
}
Album.prototype = {
init: function(){
},
loadImages: function(){
}
};
$('.album').each(function(){
var album = new Album(this);
});
I need to access the album variable that I passed in to the class Album in the init function, so I have to store it in this.album. However I don't understand that why console.log(this.album === album) is true but console.log($(this.album) === $(album)) is false
I need to use jquery in prototype, is there other way to do so? Thanks.
$(this.album).get(0) === $(album).get(0)should also return true ifthis.album === albumreturns true. But each time you wrap a DOM element inside the jQuery notation (with$) you will get a new reference, like Alex Wayne explained below.