Skip to content

Instantly share code, notes, and snippets.

@MagicControl
Last active May 2, 2017 08:14
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 MagicControl/2182516a220dd9721165db2654fa4aba to your computer and use it in GitHub Desktop.
Save MagicControl/2182516a220dd9721165db2654fa4aba to your computer and use it in GitHub Desktop.
// 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(){A.call(this);}
// 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