How to set up JavaScript namespace and classes properly?
问题 It seems there are so many ways to set up a JavaScript application so it is confusing as to which one is correct or best. Are there any difference to the below techniques or a better way of doing this? MyNamespace.MyClass = { someProperty: 5, anotherProperty: false, init: function () { //do initialization }, someFunction: function () { //do something } }; $(function () { MyNamespace.MyClass.init(); }); Another way: MyNamespace.MyClass = (function () { var someProperty = 5; var anotherProperty