Skip to content

Instantly share code, notes, and snippets.

@suissa
Created May 14, 2012 11:00
Show Gist options
  • Save suissa/2693318 to your computer and use it in GitHub Desktop.
Save suissa/2693318 to your computer and use it in GitHub Desktop.
Constructor with javascript
Function.prototype.extend = function (proto) {
var constructor = proto.constructor;
constructor.prototype = Object.create(this.prototype, Object.getOwnPropertyDescriptors(proto));
return constructor;
};
var Person = Object.extend({
constructor: function (name) {
this.name = name;
}
});
var SomeGuy = Person.extend({
constructor: function (foo) {
Person.apply(this, arguments);
},
method: function () {
}
});
var dude = new SomeGuy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment