« Back to Index

JavaScript: inheritance by proxy

View original Gist on GitHub

inherit-by-proxy.js

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