Last active
May 2, 2017 08:14
-
-
Save MagicControl/2182516a220dd9721165db2654fa4aba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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