I have an instance of a constructor called SlideShow and I wanted to know what the scope of a variable with the key word var would be.
I understand this refers to the object itself but not sure what scope the itemWidth would be. I presume its local to the function but if the function is global does this mean the var inside it is too? can var itemWidth be accessed from anywhere else?
function SlideShow( width, height ){
this.width = width;
this.height = height;
var itemWidth = 400;
}
I presume the var inside the update method with is part of the objects prototype object would be local to that function and not global.
SlideShow.prototype.update = function( dir ){
var dir = value;
}
functiondefines scope. Anything declared inside a function withvaris local, and visible only inside that function (or functions declared inside it). In both of your examples, the var in question is only visible inside the function.