Last active
December 15, 2015 13:29
-
-
Save yckart/5267295 to your computer and use it in GitHub Desktop.
A class factory.
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
| /** | |
| * Class | |
| * A class factory | |
| */ | |
| function Class(parent, members) { | |
| // prepare single-inheritance | |
| members = members || parent; | |
| // setup proxy | |
| var Proxy = function () {}; | |
| Proxy.prototype = (parent || Class).prototype; | |
| // setup constructor | |
| members.init = members.init || function () {}; | |
| var Shell = members.init; | |
| // setup inheritance | |
| Shell.prototype = new Proxy(); | |
| // setup identity | |
| Shell.prototype.constructor = Shell; | |
| // setup augmentation | |
| Shell.extend = function (items) { | |
| for (var item in items) { | |
| if (!Shell.prototype.hasOwnProperty(item)) { | |
| Shell.prototype[item] = items[item]; | |
| } | |
| } | |
| return Shell; | |
| }; | |
| // attach members and return the new class | |
| return Shell.extend(members); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment