In the code below, I can't access this.children
from init()
. Why can't I access it? How can I change my code to be able to access it?
Important: this.camera
has to be accessible from outside the object. init()
has to be private.
Please try not to only give a solution, but more of an explanation. I want to understand what I do.
PROJECT.element = function () {
this.children = [1,2,5,8];
///////////
//PRIVATE FUNCTIONS
//Initialisation of the object.
var init = function () {
this.children.push(9);
}
init();
};
To keep Andy happy:
PROJECT.element.prototype.constructor = PROJECT.element;
var thisAwesomeVariableWithGreatNameForAndy = new PROJECT.element();
(I am sure that there are question similar to this one already, and I did read a nice amount of them, but it's hard to use the search function on "scope" and "object", because there are -a lot- of question)