I wrote a simple test script in fiddle: http://jsfiddle.net/resting/qfCue/
What I'm trying to do is to set the margin property as 2, and let obj.foptions.labelMargin
and obj.marginClone
take in this value.
I know its possible to change in value in obj.foptions.labelMargin
and obj.marginClone
directly. But that wouldn't allow me to "change one place, change in all places".
Instead, both obj.foptions.labelMargin
and obj.marginClone
are undefined
.
How do I get this.margin
to read as 2?
Code:
var obj= {
margin: 10,
setMargin: function(val) { this.margin = val; },
foptions: { labelMargin: this.margin },
marginClone: this.margin
}
obj.setMargin(2);
console.dir(obj.foptions);
console.log(obj.marginClone);
console.log(obj.margin);