Created
October 16, 2012 08:20
-
-
Save jrcryer/3898014 to your computer and use it in GitHub Desktop.
Simple js class library
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
(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