Created
February 19, 2013 09:25
-
-
Save beala/4984326 to your computer and use it in GitHub Desktop.
Fun with prototype inheritance in JS.
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
// Create constructors for Parent, Sub1, and Sub2. | |
function Parent(){} | |
function Sub1(){} | |
function Sub2(){} | |
// Sub1 and Sub2 inherit from Parent. | |
Sub1.prototype = Sub2.prototype = new Parent(); | |
(new Sub1()) instanceof Sub2 // true. Wat? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment