Created
June 25, 2012 22:56
-
-
Save anthonybrown/2991986 to your computer and use it in GitHub Desktop.
Custom 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
var Class = function(parent){ | |
var klass = function(){ | |
this.init.apply(this, arguments); | |
}; | |
// Change klass' prototype | |
if (parent) { | |
var subclass = function() { }; | |
subclass.prototype = parent.prototype; | |
klass.prototype = new subclass; | |
}; | |
klass.prototype.init = function(){}; | |
// Shortcuts | |
klass.fn = klass.prototype; | |
klass.fn.parent = klass; | |
klass._super = klass.__proto__; | |
/* include/extend code... */ | |
return klass; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Custom javascript library