Have you tried using the implementation of Node.js? (It uses Object.create , so it may or may not work in the browsers you care about ). Here's the implementation, from https://github.com/joyent/node/blob/master/lib/util.js :
inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); };
Another method is used by CoffeeScript, which compiles
class Super class Sub extends Super
to
var Sub, Super, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Super = (function() { function Super() {} return Super; })(); Sub = (function(_super) { __extends(Sub, _super); function Sub() { return Sub.__super__.constructor.apply(this, arguments); } return Sub; })(Super);
source share