For your purposes, I just make it the prototype of the new constructor of objects and redefine the ones you want to change. Cloning in JS becomes messy due to a circular link problem, so this may not be the fast and dirty solution you were hoping for.
function cloneEventObj(eventObj, overrideObj){ if(!overrideObj){ overrideObj = {}; } function EventCloneFactory(overProps){ for(var x in overProps){ this[x] = overProps[x]; } } EventCloneFactory.prototype = eventObj; return new EventCloneFactory(overrideObj); }
In this case, the "cloned" object is the prototype of the object of the new object. 'this is.' properties are checked before the prototype object to be redefined. Or you can just attach properties after creating the object.
Erik reppen
source share