I have an object that looks like this:
var BigObject = {
'CurrentInt': 0,
'CurrentBool': false,
'CurrentObject': {}
}
And then, I declare SomeObject like this:
var SomeObject = {
'SomeString': "",
'SomeInt': 0
}
These two definitions are for the objects when they’re in their initial state, sort of like a type definition I guess. Now I want to assign a new SomeObject to BigObject['CurrentObject']. I tried this:
BigObject['CurrentObject'] = new SomeObject();
But it’s not working. At the moment, I just do a straight assignment by reference BigObject['CurrentObject'] = SomeObject; and then when I need to reset the values of SomeObject, I just run a function that redeclares each property of SomeObject in its initial stage.
But how can I use the new keyword to create a reusable object type that’s a property of BigObject.
Thanks.
If you’re defining a type, you should use a constructor function:
Once you’ve defined these constructors, you can
newthem (create instances):