In fact, it is possible to do this with Object.create . It will not work for "undefined" properties. But for those who have been assigned a default value.
var defaults = { a: 'test1', b: 'test2' };
Then, when you create your properties object, you do this with Object.create
properties = Object.create(defaults);
Now you will have two objects where the first object is empty, but the prototype points to the defaults object. To check:
console.log('Unchanged', properties); properties.a = 'updated'; console.log('Updated', properties); console.log('Defaults', Object.getPrototypeOf(properties));
Nils May 12 '14 at 18:45 2014-05-12 18:45
source share