How do you create a global constructor object in javascript?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

How do you create a global constructor object in javascript?

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

What are you trying to do with this constructor thing? Does the prototype model that Javascript uses not work for the situation?
Post Reply