Skip to content

Instantly share code, notes, and snippets.

@wkronemeijer
Created November 2, 2013 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wkronemeijer/7284266 to your computer and use it in GitHub Desktop.
Save wkronemeijer/7284266 to your computer and use it in GitHub Desktop.
extend arbitrary classes with your prepoerties; this works just like the Backbone.js variant, but is now situated under Object.
Object.defineProperty(Object.prototype, 'extend', {value: function (proto_props) {
var child = proto_props.hasOwnProperty('constructor') ?
proto_props.constructor :
function () {child.__super__.constructor.apply(this, arguments);};
child.prototype = Object.create(this.prototype);
child.prototype.constructor = child;
Object.keys(proto_props).forEach(function (key) {
child.prototype[key] = proto_props[key];
});
child.__super__ = this.prototype;
return child;
}}); //snatched from backbone.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment