I Get an 'undefined' error when trying to run the following code. It happens on the line this.xPositionForPageAtIndex(selectedPageNumber). When I try to log this all of the instance properties are there, except the function.
function Gallery(div) {
this.count = 5;
this.pageWidth = 500;
this.selectedPage = 1;
this.xPositionForPageAtIndex = function(pageIndex) {
if (pageIndex < 1 || pageIndex > this.count) {
return 0.0;
}
return (pageIndex - 1) * this.pageWidth;
}
}
Gallery.prototype = {
set selectedPage(selectedPageNumber) {
var page = this.pages[((selectedPageNumber) + 1)];
if (!page.classList.contains("animate")) {
page.classList.add("animate");
}
if (!page.classList.contains("final")) {
page.classList.add("final");
}
console.log(this);
this.binder.setAttribute("-webkit-transform", "translateX(" -this.xPositionForPageAtIndex(selectedPageNumber) + "px)");
this.selectedPage = page;
}
}
I am a little new to Javascript OOP, but I don't think I really know enough terminology to be able to properly research this answer.
+beforethis.xPosition...on the line where you set the webkit attributesetmight want to have a look at this ejohn.org/blog/javascript-getters-and-setters