Not really.
Depending on what you really need, one option might be to set o as a prototype for a new object.
var o = {}; (function(x){ var obj = Object.create( x ); obj.foo = 'foo'; obj.bar = 'bar'; })(o); alert( o.foo );
So, any properties added to obj will not be added to o . Any properties added to obj with the same property name as the property in o will be the shadow property of o .
Of course, any properties added to o will be accessible from obj if they are not shaded, and all objects with o in the prototype chain will see the same updates to o .
Also, if obj has a property that refers to another object, such as Array, you will need to shadow this object before adding members to the object, otherwise these members will be added to obj , and will be used for all objects with obj in the prototype chain .
var o = { baz: [] }; (function(x){ var obj = Object.create( x ); obj.baz.push( 'new value' ); })(o); alert( o.baz[0] );
Here you can see that since you did not shade the array in baz to o using the baz property on obj , the o.baz array will be changed.
So, first you need to shade it:
var o = { baz: [] }; (function(x){ var obj = Object.create( x ); obj.baz = []; obj.baz.push( 'new value' ); })(o); alert( o.baz[0] );
user113716 Sep 27 '11 at 18:48 2011-09-27 18:48
source share