I want to know how to create a private attribute in a Javascript class. I tried this:
function Class1(selector)
{
//calling the constructor
Constructor();
//private attribute
var $container = null;
function Constructor()
{
$container = $(selector);
//Shows that container is an object
alert($container);
}
function Foo()
{
//Shows that container is null
alert($container);
}
result {
Foo : Foo
};
}
I supposed that in “Constructor” it creates a new variable $container and assign the object to it. I want to know how I am suposed to assign the value to the attribute $container of the object and not the local variable in the function Constructor.
this is because you first call
Constructor()and after that you assignnullto$containerIf you switch that around you will get the desired result:
http://jsfiddle.net/R8RG5/