Skip to content

Instantly share code, notes, and snippets.

@vstarck
Created March 18, 2013 18:21
Show Gist options
  • Save vstarck/5189484 to your computer and use it in GitHub Desktop.
Save vstarck/5189484 to your computer and use it in GitHub Desktop.
function Parent() {
this.array = [1, 2, 3];
}
function Child() {
}
Child.prototype = new Parent;
var c1 = new Child;
c1.array; // [1, 2, 3]
c1.array.push(4);
var c2 = new Child;
c2.array; // [1, 2, 3, 4]
function Parent() {
this.array = [1, 2, 3];
}
function Child() {
Parent.call(this); // <--------------------- The fix
}
Child.prototype = new Parent;
var c1 = new Child;
c1.array; // [1, 2, 3]
c1.array.push(4);
var c2 = new Child;
c2.array; // [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment