Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 17, 2010 06:58
Show Gist options
  • Save isaacs/306377 to your computer and use it in GitHub Desktop.
Save isaacs/306377 to your computer and use it in GitHub Desktop.
Object.deepCreate = function deepCreate (o) {
var n = Object.create(o);
for (var i in o) if (o.hasOwnProperty(i) && typeof o[i] === "object" && o[i]) {
n[i] = Object.deepCreate(o[i]);
}
return n;
};
o = {foo:{bar:1}};
n = Object.deepCreate(o);
n.foo.bar = 2;
require("assert").equal(o.foo.bar, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment