Instantly share code, notes, and snippets.

What would you like to do?
// 1. Call superclass constructor in the constructor of a child class with this of the child class:
//var A = function(){} - our superclass
var B = function(){;}
// 2. Create a new object based on superclass prototype and assign it to the prototype of a child class:
B.prototype = Object.create(A.prototype);
// 3. Rewrite child class constructor:
B.prototype.constructor = B;
//Let's check it:
b instanceof B // true
b instanceof A // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment