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

3.6.5 CONSTRUCT

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

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

crx_registerClass("ExampleClass2",
{
   EXTENDS: "ExampleClass1",
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
      {
         //   Calling the parent class's constructor explicitly to
         //      pass the necessary parameters
         this.PARENT.CONSTRUCT(pValue);
      }
   }
});

crx_registerClass("ExampleClass3",
{
   EXTENDS: "ExampleClass2",
   PUBLIC:
   {
      CONSTRUCT: function(pValue)
      {
         //   Calling the parent class's constructor explicitly to
         //      pass the necessary parameters
         this.PARENT.CONSTRUCT(pValue);

         //   The following are examples of what would lead to
         //      fatal errors:
         //   - RECURSIVE CALL TO CONSTRUCTOR
         //      this.CONSTRUCT(pValue);
         //   - SECOND CALL TO PARENT's CONSTRUCTOR
         //      this.PARENT.CONSTRUCT(pValue);
         //   - CALL TO GRAND PARENT's CONSTRUCTOR
         //      this.PARENT.PARENT.CONSTRUCT(pValue);
      }
   }
});

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

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

crx_registerClass("ExampleClass2",
{
   "VERBOSE": 1,
   "extends": "ExampleClass1",
   "public CONSTRUCT": function(pValue)
   {
      //   Calling the parent class's constructor explicitly to
      //      pass the necessary parameters
      this.PARENT.CONSTRUCT(pValue);
   }
});

crx_registerClass("ExampleClass3",
{
   "VERBOSE": 1,
   "extends": "ExampleClass2",
   "public CONSTRUCT": function(pValue)
   {
      //   Calling the parent class's constructor explicitly to
      //      pass the necessary parameters
      this.PARENT.CONSTRUCT(pValue);

      //   The following are examples of what would lead to
      //      fatal errors:
      //   - RECURSIVE CALL TO CONSTRUCTOR
      //      this.CONSTRUCT(pValue);
      //   - SECOND CALL TO PARENT's CONSTRUCTOR
      //      this.PARENT.CONSTRUCT(pValue);
      //   - CALL TO GRAND PARENT's CONSTRUCTOR
      //      this.PARENT.PARENT.CONSTRUCT(pValue);
   }
});

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

instance.test();
I am a new privateVar