Created
March 18, 2013 18:21
-
-
Save vstarck/5189484 to your computer and use it in GitHub Desktop.
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 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] |
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 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