Created
August 19, 2011 23:28
-
-
Save stevenlr/1158299 to your computer and use it in GitHub Desktop.
Minimal Javascript OOP
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
var Class = function () { | |
var F, methods = {}, parent = {}, i, statics = {}, args; | |
args = Array.prototype.slice.call(arguments); | |
if (args.length == 2) | |
parent = args.shift(); | |
methods = args[0]; | |
if (methods._statics) { | |
statics = methods._statics; | |
delete methods["_statics"]; | |
} | |
F = methods.constructor instanceof Function ? methods.constructor : function () {}; | |
if (parent) | |
for (i in parent.prototype) | |
F.prototype[i] = parent.prototype[i]; | |
for (i in methods) | |
F.prototype[i] = methods[i]; | |
if (parent) | |
F.prototype.superc = parent; | |
for (i in statics) | |
F[i] = statics[i]; | |
return F; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment