Was looking through best practices when dealing with external objects for example and ran across this article about why not to modify objects you do not own.
Reasoning is fairly sound, my question is how would I go about implementing this. For reference my code behaviour is current like this (custom object being owned by a 3rd party, Google maps):
var cObj = new customObject();
//I need to custom properties in addition to what Google provides
//So I insert new properties:
cObj.myProp1 = 1;
Article gives good reasons as to why its a bad practice therefore I do this:
function objWrapper(e){
var cObj = e.cObj ? e.cObj : null;
var myProp1 = e.myProp1 ? e.myProp1 : null;
}
//Here I create a copy of my wrapper and insert the Custom Object into it:
var obj - new objWrapper({});
var cObj = new customObject();
//Then I insert the cObj reference to the wrapper
obj.cObj = cObj;
This approach works fine when dealing with just variables but if say I ever need to access another child of the obj I would need to add in a circular reference like so:
cObj.obj = obj;
Which is not ideal, with a OO language I can see how to do this properly, not quite sure how to proceed in JS. I don't see how prototypes would really help here either.
PS: The actual code I'm working with is here but a more generalised explanation is what I'm looking for.