Created
May 14, 2012 11:00
-
-
Save suissa/2693318 to your computer and use it in GitHub Desktop.
Constructor with javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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