I’m taking an existing JS library I wrote up some time ago, and trying to organize it under a common namespace…Here is an example of the technique I am trying to use:
var NameSpace = new function () { var privateMember = []; function privateMethod() {}; return { PublicMethod1 : function(arg, arg2) { // etc }, PublicMethod2 : function () { // etc }, PublicMethod3 : function(arg, arg2) { // etc } }; }();
From what I can tell, this should work perfectly, however I get a Syntax Error on this line:
PublicMethod1 : function(arg, arg2)
Can anyone see some obvious problem with this technique?
Problem was real tricky, return and { should be on the same line apparently. Also new [] was not valid, I fixed this for you too.