Skip to content

Instantly share code, notes, and snippets.

@Krewn
Created December 18, 2016 14:50
Show Gist options
  • Save Krewn/5a44485198300edeefb1dd549c5d5de5 to your computer and use it in GitHub Desktop.
Save Krewn/5a44485198300edeefb1dd549c5d5de5 to your computer and use it in GitHub Desktop.
This is one way to work inheritance in js. Data variables are separated from functional ones by calls to prototype.
a = function(){
this.v1 = "Hello";
this.v2 = "World";
}
a.prototype.print=function(){
alert(this.v1.concat(this.v2))
}
b = function(){
a.call(this);
this.v1 = "hey";
}
b.prototype = Object.create(a.prototype);
let myB = new b();
myB.print();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment