What are the drawbacks of this Classing format?
- by Keysle
This is a 3 layer example of my classing format
function __(_){return _.constructor}
//class
var _ = ( CLASS = function(){
this.variable = 0;
this.sub = new CLASS.SUBCLASS();
}).prototype;
_.func = function(){
alert('lvl'+this.variable);
this.sub.func();
}
_.divePeak = function(){
alert('lvl'+this.variable);
this.sub.variable += 5;
}
//sub class
_ = ( __(_).SUBCLASS = function(){
this.variable = 1;
this.sub = new CLASS.SUBCLASS.DEEPCLASS();
}).prototype;
_.func = function(){
alert('lvl'+this.variable);
this.sub.func();
}
//deep class
_ = ( __(_).DEEPCLASS = function(){
this.variable = 2;
}).prototype;
_.func = function(){
alert('lvl'+this.variable);
}
Before you blow a gasket, let me explain myself. The purpose behind the underscores is to accelerate the time needed to specify functions for a class and also specify sub classes of a class. To me it's easier to read. I KNOW, this does interfere with underscore.js if you intend to use it in your classes. I'm sure _.js can be easily switched over to another $ymbol though ... oh wait, But I digress.
Why have classes within a class?
because
solar.system()
and
social.system()
mean two totally different things but it's convenient to use the same name.
Why user underscores to manage the definition of the class?
because "Solar.System.prototype" took me about 2 seconds to type out and 2 typos to correct.
It also keeps all function names for all classes in the same column of texts, which is nice for legibility.
All I'm doing is presenting my reasoning behind this method and why I came up with it. I'm 3 days into learning OO JS and I am very willing to accept that I might have messed up.