javascript assigning new object as object property -


i have object looks this:

var bigobject = {     'currentint': 0,     'currentbool': false,     'currentobject': {} } 

and then, declare someobject this:

var someobject = {       'somestring': "",       'someint': 0 } 

these 2 definitions objects when they're in initial state, sort of type definition guess. want assign new someobject bigobject['currentobject']. tried this:

bigobject['currentobject'] = new someobject(); 

but it's not working. @ moment, straight assignment reference bigobject['currentobject'] = someobject; , when need reset values of someobject, run function redeclares each property of someobject in initial stage.

but how can use new keyword create reusable object type that's property of bigobject.

thanks.

if you're defining type, should use constructor function:

var someobject = function() {     this.somestring = "";     this.someint = 0; }  var bigobject = function() {     this.currentint = 0;     this.currentbool = false;     this.currentobject = new someobject(); } 

once you've defined these constructors, can new them (create instances):

var mybigobject = new bigobject(); console.log(mybigobject.currentobject); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - EclipseLink JPA Object is not a known entity type -

java - Need to add SOAP security token -