Skip to content

Instantly share code, notes, and snippets.

@beala
Created February 19, 2013 09:25
Show Gist options
  • Save beala/4984326 to your computer and use it in GitHub Desktop.
Save beala/4984326 to your computer and use it in GitHub Desktop.
Fun with prototype inheritance in JS.
// 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