Clone/copy

Use ES5 to clone/copy objects

by Rodolfo Hernandez

HTML

<a href="https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-an-object">An answer to a SO question</a>

JavaScript

var c = { p:1, e: "what" } // only with primitives inner objects..
var c2 = Object.create(c);
c2.e = "how";
console.log(c, c2)

// if you have objects would not work:
var c = { p:1, e: {a:"what"} } 
var c2 = Object.create(c);
c2.e.a = "how";
console.log(c, c2)