Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created July 14, 2009 02:17
Show Gist options
  • Select an option

  • Save jaredatron/146658 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/146658 to your computer and use it in GitHub Desktop.
/* Clone With Inheritance
*
* Creates a new object that inherits from the given object so it will reflect any
* future changes to the original object
*/
Object.cloneWithInheritance = function cloneWithInheritance(source){
var sourceClass = function(){};
sourceClass.prototype = source;
return new sourceClass();
};
Hash.prototype.cloneWithInheritance = function cloneWithInheritance(){
var hash = new Hash();
hash._object = Object.cloneWithInheritance(this._object);
return hash;
};
Object.extendWithInheritance = function extendWithInheritance(source, extension){
return Object.extend(Object.cloneWithInheritance(source),extension);
};
Hash.prototype.mergeWithInheritance = function mergeWithInheritance(source){
return this.cloneWithInheritance().update(source);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment