Class - AbrahamTewa/JsPackage GitHub Wiki
Creation of a new class
All in one example : `var ParentClass = Class({ a : 1 // Public attribute , getA : function() { return this.a } // Public Method
, b : Private.Static.Constant(2) // Constants must be statics , getB : Public.Static.Method( function() { return this.b; }
, c : Protected(3) , getC : Public.Method( function() { return this.c } });
var parentInstance = new ParentClass();
console.log(parentInstance.a) // undefined console.log(parentInstance.getA()) // 1
console.log(parentInstance.b) // undefined console.log(parentInstance.getB()) // 2
console.log(ParentClass.b) // undefined console.log(ParentClass.getB()) // 2
var ChildClass = Class({ $ : { extends : ParentClass , final : true , initialize : function(a, c) { this.a : a; this.c : b; } } , getA : function() { return this.a; } , setC : Method.Static( function(obj, c) { this(obj).c = c; // We open the object to pass the value } });
var childInstance = new ChildClass('a', 'b');
console.log(childInstance.b()); // undefined : Only the class can access to b console.log(ChildClass.getB()); // 2 console.log(childInstance.getB()); // 2
console.log(childInstance.getC())
` Private, Constant, Public, Protected, Static, Method and Attribute are descriptors.