I am defining a simple object "Browser" which is allowing to display "previous" and "next" image from a list.
function Browser(image, elements) {
this.current = 0;
this.image = image;
this.elements = elements;
}
Browser.prototype.next = function () {
if (++this.current >= this.elements.length) {
this.current = 0;
}
return this.show(this.current);
};
Browser.prototype.prev = function () {
if (--this.current < 0) {
this.current = this.elements.length - 1;
}
return this.show(this.current);
};
Browser.prototype.show = function (current) {
this.image.src = this.elements[current];
return false;
};
This code is almost liked by JSlint. But the Google Closure Compiler in "advanced optimization" does not compile it.
It says:
JSC_USED_GLOBAL_THIS: dangerous use of the global this object at line 3 character 0
this.current = 0;
JSC_USED_GLOBAL_THIS: dangerous use of the global this object at line 4 character 0
this.image = image;
JSC_USED_GLOBAL_THIS: dangerous use of the global this object at line 5 character 0
this.elements = elements;
Which tells me that I do not understand javascript oop.
What am I doing wrong?