-
-
Save solomon081/2955859 to your computer and use it in GitHub Desktop.
ClassLib
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); | |
} | |
if (parent) { | |
var subclass = function() {}; | |
subclass.prototype = parent.prototype; | |
klass.prototype = new subclass; | |
} | |
klass.prototype.init = function(){} | |
klass.addInstanceFunc = function(name, func) { | |
eval("this.prototype." + name + " = " + func); | |
} | |
klass.addClassFunc = function(name, func) { | |
eval("this." + name + " = " + func); | |
} | |
klass.addSubclass = function(su) { | |
eval("this." + su + " = " + su) | |
} | |
return klass; | |
} |
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
>>> User = new Class(); | |
>>> User.addInstanceFunc("isUser", function(){console.log("Yeppers!")}) | |
>>> userOne = new User(); | |
>>> userOne.isUser(); | |
Yeppers! | |
>>> User.addClassFunc("allUsers", function(){console.log("Just that guy...")}) | |
>>> User.allUsers(); | |
Just that guy... | |
>>> Parent = new Class(); | |
>>> Parent.addInstanceFunc("noActualUse",function(){console.log("This has no use!")}); | |
>>> Child = new Class(Parent); | |
>>> joey = new Child(); | |
>>> joey.noActualUse(); | |
This has no use! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment