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.
$container = $(selector);will do that, but it seems you are never callingConstructoredit: missed the first line, yeah, the statements are just in the wrong order. That said, I'm not a big fan of emulating visibility this way. IMO it makes the code too complex and inflexible. Rather document your code properly.