Created
March 11, 2014 18:32
-
-
Save sbstp/9492068 to your computer and use it in GitHub Desktop.
This file contains 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
// allow object inheritance | |
Object.extends = function (ctor, superCtor) { | |
// collect objects already on the prototype to "save" them | |
var descriptors = {}; | |
// copy properties from old prototype | |
Object.getOwnPropertyNames(ctor.prototype).forEach(function (propertyName) { | |
descriptors[propertyName] = Object.getOwnPropertyDescriptor(ctor.prototype, propertyName); | |
}, this); | |
// proto | |
var newProto = Object.create(superCtor.prototype, descriptors); | |
ctor.prototype = newProto; | |
ctor.$super = superCtor; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment