What is the cleanest format for writing javascript objects?
Currently I write mine in the following format
if (Namespace1 == null) var Namespace1 = {};
i
The module pattern may help you out here:
var Namespace1 = Namespace1 || {};
Namespace1.Namespace2 = Namespace1.Namespace2 || {};
Namespace1.Namespace2.Class1 = function(param1, param2) {
// define private instance variables and their getters and setters
var privateParam = param1;
this.getPrivateParam = function() { return privateParam; }
this.publicParam1 = param2;
return {
init: function() {
alert('hi from Class1');
}
}
} ();
You can read more about it here: http://yuiblog.com/blog/2007/06/12/module-pattern/
Namespace1.Namespace2.Class1.init();