Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created May 10, 2013 04:25
Show Gist options
  • Save jeremyckahn/5552373 to your computer and use it in GitHub Desktop.
Save jeremyckahn/5552373 to your computer and use it in GitHub Desktop.
Proxy-based inheritance pattern in JavaScript.
function inherit (child, parent) {
function proxy () {};
proxy.prototype = parent.prototype;
child.prototype = new proxy();
};
function Parent () {}
function Child () {}
inherit(Child, Parent);
var child = new Child();
console.log(child instanceof Child); // true
console.log(child instanceof Parent); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment