Created
July 14, 2009 02:17
-
-
Save jaredatron/146658 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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