Skip to content

Instantly share code, notes, and snippets.

@ChillyBwoy
Created June 5, 2011 22:59
Show Gist options
  • Save ChillyBwoy/1009517 to your computer and use it in GitHub Desktop.
Save ChillyBwoy/1009517 to your computer and use it in GitHub Desktop.
JavaScript inherit
/* simple */
var extends = function(child, parent) {
var F = function() { }
F.prototype = parent.prototype
child.prototype = new F()
child.prototype.constructor = child
child.superclass = parent.prototype
}
/* from CoffeeScript */
var extends = function(child, parent) {
for (var key in parent) {
if (Object.prototype.hasOwnProperty.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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment