I am trying to create a reusable javascript object (I want to use new). When I attempt to new up one of my custom objects I get an error:
"org.myorg.sadp.section.sadpSection is not a constructor"
I am modularizing my JS for namespace reasons. I wonder if that is the problem:
if (!window.org) var org = { myorg: {} };
if (!org.myorg) org["myorg"] = { sadp: {} };
if (!org.myorg.sadp) org.myorg["sadp"] = {};
org.myorg.sadp.section = (function(ns) {
if (ns.section) {
return ns;
}
else {
ns.section = {};
}
ns.section.sadpSection = function(name) {
this.name = name;
this.isCompleted = false;
this.booleanQuestions = new Array();
this.multipleChoiceQuestions = new Array();
this.sliders = new Array();
return true;
}
return ns;
} (org.myorg.sadp))
This results in the error:
var myObj = new org.myorg.sadp.section.sadpSection("test");
What am I doing wrong here?
Thanks!