Page 1 of 1

How do you create a global constructor object in javascript?

Posted: Fri Aug 09, 2013 2:57 pm
by drayarms
Hello folks,

I think the question is rather self explicit. I need to create an object from which I can create instances during the life of my application. So I opted for a constructor object. I just don't know how to make it global so that all my scripts can have access to it. I have tried including it in a namespace without succes

Code: Select all


var myNamespace = {

     myConstructorObject:function(){

          //Attributes and methods of my constructor go here

     }

}

Also tried this...

Code: Select all


var myNamespace = {

     function myConstructorObject(){

          //Attributes and methods of my constructor go here

     }

}


In both cases, I create a new instance of my constructor like so
var newInstance = myNamespace.myConstructorObject

I also tired creating the constructor object as a global object outside of my namespace like so

Code: Select all


myConstructorObject = function(){

     //Attributes and methods


}


Nothing works as intended. Who knows what I'm not doing right?

Re: How do you create a global constructor object in javascr

Posted: Fri Aug 09, 2013 3:09 pm
by requinix
What are you trying to do with this constructor thing? Does the prototype model that Javascript uses not work for the situation?