I was reading about the best methods to create objects in javascript and found an interesting solution here.
var Foo = function()
{
var privateStaticMethod = function() {};
var privateStaticVariable = "foo";
var constructor = function Foo(foo, bar)
{
var privateMethod = function() {};
this.publicMethod = function() {};
};
constructor.publicStaticMethod = function() {};
return constructor;
}();
I have been playing with this structure but I was wondering how can I do a few things.
How can I access
privateStaticVariable
orprivateStaticMethod
from withinconstructor.publicStaticMethod
?If I create a second public method like
constructor.secondPublicStaticMethod = function(){};
, how can I access it from withinconstructor.publicStaticMethod
?If I was to instantiate this object, how could I access all static properties and methods from within
constructor
?