Skip to content

Instantly share code, notes, and snippets.

@karenpeng
Created May 25, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenpeng/cbe53d483645671258f2 to your computer and use it in GitHub Desktop.
Save karenpeng/cbe53d483645671258f2 to your computer and use it in GitHub Desktop.
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