I have one here:
What I noticed is that in this framework, all variables are static ( they are on the prototype chain ), and are only "instance" based if you set them in the constructor.
I'm using these terms from CS101 usually taught via Java.
Is there a better way to do this?
By default I set instance variables to a string 'instance' which will be replaced once the constructor is called.
var klass = function (obj, config_module) {
if (config_module === 'constructor') {
var object_public;
if (obj.constructor) {
object_public = obj.constructor;
delete obj.constructor;
}
_.some(obj, function (val, key) {
object_public.prototype[key] = val;
});
return object_public;
}
};
var Test = klass({
// instance, set in constructor
A : 'instance',
// static, not set in constructor
B : 4,
constructor: function (some_var) {
this.A = some_var;
},
get: function () {
return 2;
},
set: function () {
}
}, 'constructor');
var instanceA = new Test('A');
var instanceB = new Test('B');
console.log('Start');
console.log(instanceA.A);
console.log(instanceB.A);