Skip to content

Instantly share code, notes, and snippets.

@jrcryer
Created October 16, 2012 08:20
Show Gist options
  • Save jrcryer/3898014 to your computer and use it in GitHub Desktop.
Save jrcryer/3898014 to your computer and use it in GitHub Desktop.
Simple js class library
(function(exports) {
var Class = function(parent) {
var klass = function() {
this.init.apply(this, arguments);
};
if(parent) {
var subclass = function(){};
subclass.prototype = parent.prototype;
klass.prototype = new subclass;
}
klass.prototype.init = function(){};
klass.fn = klass.prototype;
klass.fn.parent = klass;
klass._super = klass.__proto__;
klass.proxy = function(func) {
var self = this;
return (function() {
func.apply(self, arguments);
});
};
klass.fn.proxy = klass.proxy;
klass.extend = function(obj) {
var extended = obj.extended;
for(i in obj) {
klass[i] = obj[i];
}
if(extended) extended(klass);
};
klass.include = function(obj) {
var included = obj.included;
for(i in obj) {
klass.fn[i] = obj[i];
}
if(included) included(klass);
};
return klass;
};
exports.Class = Class;
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment