Last active
December 27, 2015 00:39
-
-
Save matthewrobb/7239518 to your computer and use it in GitHub Desktop.
Recursive object descent and prototype reassignment
This file contains 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
function inheritize(root){ | |
Object.keys(root).forEach(function(key){ | |
var branch = root[key]; | |
if (typeof branch === "object") { | |
Object.keys(branch).forEach(function(key){ | |
var leaf = branch[key]; | |
if (typeof leaf === "object" && typeof root[key] === "object") { | |
// In the HOPEFULLY near future this would be replaced with: | |
// Object.setPrototypeOf(leaf, root[key]); | |
leaf.__proto__ = root[key]; | |
} | |
}); | |
inheritize(branch); | |
} | |
}); | |
return root; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment