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.4 PARENT

The class keyword PARENT is equivalent to casting 'this' to the parent class using 'CAST'. However, 'PARENT' is faster than 'CAST' and more readable. 'PARENT', unlike 'this' for example, is safe to pass to and from functions.

JS (Tree)
crx_registerClass("ExampleClass1",
{
   PUBLIC:
   {
      VARS:
      {
         "publicVar": "I am ExampleClass1's publicVar"
      }
   }
});
crx_registerClass("ExampleClass2",
{
   EXTENDS: "ExampleClass1",
   PUBLIC:
   {
      VARS:
      {
         "publicVar": "I am ExampleClass2's publicVar"
      },
      FUNCTIONS:
      {
         "publicFunction": function()
         {
            console.log(this.publicVar);

            //   Printing "publicVar" of parent class
            console.log(this.PARENT.publicVar);
            //   Which is equivalent to
            console.log(this.CAST("ExampleClass1").publicVar);
         }
      }
   }
});

var instance = crx_new("ExampleClass2");

instance.publicFunction();
I am ExampleClass2's publicVar
I am ExampleClass1's publicVar
I am ExampleClass1's publicVar
JS (Verbose)
crx_registerClass("ExampleClass1",
{
   "VERBOSE": 1,
   "public var publicVar": "I am ExampleClass1's publicVar"
});
crx_registerClass("ExampleClass2",
{
   "VERBOSE": 1,
   "extends": "ExampleClass1",
   "public var publicVar": "I am ExampleClass2's publicVar",
   "public function publicFunction": function()
   {
      console.log(this.publicVar);

      //   Printing "publicVar" of parent class
      console.log(this.PARENT.publicVar);
      //   Which is equivalent to
      console.log(this.CAST("ExampleClass1").publicVar);
   }
});

var instance = crx_new("ExampleClass2");

instance.publicFunction();
I am ExampleClass2's publicVar
I am ExampleClass1's publicVar
I am ExampleClass1's publicVar