Skip to content

Instantly share code, notes, and snippets.

@ositowang
Created April 5, 2019 16:40
Show Gist options
  • Save ositowang/a1eabc11f758a174f2d81397f37ea844 to your computer and use it in GitHub Desktop.
Save ositowang/a1eabc11f758a174f2d81397f37ea844 to your computer and use it in GitHub Desktop.
inheritance based on constructor stealing
/**
* Constructor stealing. As the name says, we steal the constructor from super
* class
* 1. We cant get values and methods from prototype
*/
function daddy(name) {
this.name = name;
}
function son(name) {
// reset the superclass this binding to the subclass and passed in params
daddy.call(this, name);
}
let son1 = new son('jimmy');
console.log(son1.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment