Is there an easy way to automatically add properties to objects if they don\'t allready exist?
Consider the following example:
var test = {}
test.hel
var test = {};
test.hello = test.hello || {};
test.hello.world = "Hello world!";
If test.hello is undefined, it gets set to an empty object.
If test.hello was previously defined, it stays unchanged.
var test = {
hello : {
foobar : "Hello foobar"
}
};
test.hello = test.hello || {};
test.hello.world = "Hello World";
console.log(test.hello.foobar); // this is still defined;
console.log(test.hello.world); // as is this.