Skip to content

Instantly share code, notes, and snippets.

@goatslacker
Created November 9, 2011 22:57
Show Gist options
  • Save goatslacker/1353443 to your computer and use it in GitHub Desktop.
Save goatslacker/1353443 to your computer and use it in GitHub Desktop.
Object.defineProperty(Object.prototype, "clone", {
value: function (proto) {
this.prototype = Object.create(proto.prototype, {
_super: {
value: proto.prototype
}
});
},
configurable: false,
enumerable: false,
writable: false
});
var Person = function (name) {
this.name = name;
};
Person.prototype.speak = function () {
return "Hello! I'm " + this.name;
};
var SWEngineer = function (name) {
Person.call(this, name);
};
SWEngineer.clone(Person);
SWEngineer.prototype.speak = function () {
return this._super.speak.call(this) + " and I program.";
};
var josh = new SWEngineer("Josh");
console.log(josh.speak());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment