When I do a console trace on the positionSlides method its showing slideShow as undefined.
How can this be when I clearly instantiate it in the document.ready callback. I also make sure to make this variable global so both the slideShow and the slideShowNavigation would have access to both these variables.
var slideShow, slideShowNavigation;
$(document).ready(function(){
slideShow = new SlideShow( $('#header #slideshow'), 980 );
slideShowNavigation = new SlideShowNavigation( $('#header').find("#leftArrow"), $('#header').find("#rightArrow") );
});
// SLIDE SHOW CLASS
function SlideShow( divContainer, slideWidth ){
// Check to make sure a new instance is created
if( ! (this instanceof SlideShow) ) return new SlideShow();
this.$imageContainer = divContainer;
this.slideWidth = slideWidth;
var maxImages = this.$imageContainer.children().length;
this.getMaxSlides = function(){
return maxImages;
}
this.positionSlides();
}
SlideShow.prototype.positionSlides = function(){
console.log('imageContainer = '+slideShow);
}
SlideShow.prototype.update = function( dir ){
}
// ARROW NAVIGATION FOR SLIDESHOW
function SlideShowNavigation( left, right){
if( ! (this instanceof SlideShowNavigation) ) return new SlideShowNavigation();
//this.updateArrows( slideShow.$imageContainer.find(":first") );
}
SlideShowNavigation.prototype.updateArrows = function( item ){
}
The problem is this:
That line calls your
SlideShowfunction, which callspositionSlides(), which looks forslideShow, but slideShow isn’t defined until yourSlideShowfunction returns.Instead, in positionSlides() use
thisinstead ofslideShowto refer to the instance (this way your class is independent of the variable name.