You confuse two types of variables: Local variables and member variables. var myArrayis a local variable. this.myArrayis a member variable.
, :
var ExampleObject = function() {
var myArray = new Array();
this.example = function() {
alert(myArray);
};
}
var exampleObj = new ExampleObject();
exampleObj.example();
, -:
var ExampleObject = function() {
this.myArray = new Array();
this.example = function() {
alert(this.myArray);
};
}
var exampleObj = new ExampleObject();
exampleObj.example();