Skip to content

Instantly share code, notes, and snippets.

@mlshvdv
Created March 25, 2014 10:16
Show Gist options
  • Save mlshvdv/9758646 to your computer and use it in GitHub Desktop.
Save mlshvdv/9758646 to your computer and use it in GitHub Desktop.
Copy javascript object without reference
var obj = {
a: 25,
b: 50,
c: 75,
x: function() {
alert(this.a);
}
};
var A = Object.create(obj);
var B = Object.create(obj);
A.a = 30;
B.a = 40;
B.n = 1;
alert(obj.a + " " + A.a + " " + B.a); // 25 30 40
B.x();
console.log(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment