How do you create a global constructor object in javascript?
Posted: Fri Aug 09, 2013 2:57 pm
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
Also tried this...
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
Nothing works as intended. Who knows what I'm not doing right?
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
}
}
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?