I have a namespace in my JavaScript code "MyNameSpace". I create a static JavaScript class "MyChildStaticClass" in it. I use a modular template. Below is my code:
if (typeof MyNameSpace == 'undefined' || !MyNameSpace) { var MyNameSpace = {}; } var MyNameSpace = (function(MyNameSpace) { MyNameSpace.MyChildStaticClass = (function() { var myobject; myobject = { x:function(str) { alert(str); } }; return myobject; })(); return MyNameSpace; } (MyNameSpace || {}));
The above code will be used as:
MyNameSpace.MyChildStaticClass.x('test');
and the output above will be a message test field. I have a question, what is a good way to create a static class and call methods like above? Are there any other ways to write this skill?
source share