CrxOop CrxOop: Bringing Object Oriented Programming, and Proper Prototype Based Programming, To Javascript
The aim of the library documented below is to provide developers with a solution to allow development using interfaces and classes as they are known in other object oriented programming (OOP) languages such as C++, C#, Java and PHP. Further more, V1.4 introduces structures, a generalization of the concept of prototypal inheritance, known here as POBP.
Subject
Body*
Email
SUBMIT CLOSE
Menu

5.5.3 CONSTRUCT

'CONSTRUCT' is a function. The structure keyword 'CONSTRUCT' is not to be confused with the definition keyword 'CONSTRUCT'. 'CONSTRUCT' returns the constructor function defined in the class definition, and is only available during construction. The only valid use of CONSTRUCT is to call a parent constructor using "this.CONSTRUCT('nameOfInheritedStructure')()" when an explicit call is needed. Never pass "CONSTRUCT" to functions as parameters, or from functions as returns.

JS (Tree)
crx_registerStructure("ExampleStructure1",
{
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
      {
         if(pValue !== undefined)
            {this.privateVar = pValue;}
      },
   },
   SHARED:
   {
      PUBLIC:
      {
         FUNCTIONS:
         {
            'test': function()
            {
               console.log(this.privateVar);
            }
         }
      }
   },
   PRIVATE:
   {
      VARS:
      {
         "privateVar": "I am default privateVar"
      }
   }
});

crx_registerStructure("ExampleStructure2",
{
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
         {}
   }
});

crx_registerStructure("ExampleStructure3",
{
   INHERITS: ["ExampleStructure1"],
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
      {
         //   Calling a parent structure's constructor explicitly to
         //      pass the necessary parameters
         this.CONSTRUCT("ExampleStructure1")(pValue);
      }
   }
});

crx_registerStructure("ExampleClass4",
{
   INHERITS: ["ExampleStructure2", "ExampleStructure3"],
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
      {
         //   Calling a parent structure's constructor explicitly to
         //      pass the necessary parameters
         this.CONSTRUCT("ExampleStructure3")(pValue);
      }
   }
});

var instance = crx_new("ExampleClass4", "I am a new privateVar");

instance.test();
I am a new privateVar
JS (Verbose)
crx_registerStructure("ExampleStructure1",
{
   "VERBOSE": 1,
   "public CONSTRUCT": function(pValue)
   {
      if(pValue !== undefined)
         {this.privateVar = pValue;}
   },
   "shared public function test": function()
   {
      console.log(this.privateVar);
   },
   "private var privateVar": "I am default privateVar"
});

crx_registerStructure("ExampleStructure2",
{
   "VERBOSE": 1,
   "public CONSTRUCT": function(pValue)
      {}
});

crx_registerStructure("ExampleStructure3",
{
   "VERBOSE": 1,
   "inherits": ["ExampleStructure1"],
   "public CONSTRUCT": function(pValue)
   {
      //   Calling the parent class's constructor explicitly to
      //      pass the necessary parameters
      this.CONSTRUCT("ExampleStructure1")(pValue);
   }
});

crx_registerStructure("ExampleStructure4",
{
   "VERBOSE": 1,
   "inherits": ["ExampleStructure2", "ExampleStructure3"],
   "public CONSTRUCT": function(pValue)
   {
      //   Calling a parent structure's constructor explicitly to
      //      pass the necessary parameters
      this.CONSTRUCT("ExampleStructure3")(pValue);
   }
});

var instance = crx_new("ExampleStructure4", "I am a new privateVar");

instance.test();
I am a new privateVar