Created
May 25, 2015 04:58
-
-
Save karenpeng/cbe53d483645671258f2 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.arrayInside = [1]; | |
this.numberInside = 1; | |
} | |
Parent.arrayOutside = [2]; | |
Parent.numberOutside = 2; | |
Parent.prototype.arrayPrototype = [3]; | |
Parent.prototype.numberPrototype = 3; | |
Parent.prototype.construtor = Parent; | |
function Child() { | |
Parent.call(this); | |
this.arrayInside = [4]; | |
this.numberInside = 4; | |
} | |
Child.prototype = Object.create(Parent.prototype); | |
Child.prototype.constructor = Child; | |
var parent = new Parent() | |
var child = new Child() | |
parent.arrayInside.push(5); | |
parent.__proto__.arrayPrototype.push(6); | |
console.log(parent.arrayOutside); | |
//why????? | |
//undefined?? | |
//not [2] | |
//oh it's not on __prototype__ T_T | |
console.log(parent.arrayPrototype); | |
//[3, 6] | |
parent.arrayPrototype = [0]; | |
parent.arrayPrototype.push(1); | |
console.log(parent.arrayPrototype); | |
//[0, 1] | |
console.log(child.arrayPrototype); | |
//[3, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment