Skip to content

Instantly share code, notes, and snippets.

@stevenlr
Created August 19, 2011 23:28
Show Gist options
  • Save stevenlr/1158299 to your computer and use it in GitHub Desktop.
Save stevenlr/1158299 to your computer and use it in GitHub Desktop.
Minimal Javascript OOP
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