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.2 O

'O' is a function. While 'this' allows you access to private variables and functions, as well as shared privates and shared publics, of the current instance, 'O' allows access to privates and shared privates of other instances. Internally 'O' will automatically return 'this', not 'THIS', of the object. Hence 'O' must never be passed to functions as parameters or from functions as returns, and because 'O' returns 'this', the rule applies to its return too. 'O' returns null if an error.

JS (Tree)
crx_registerStructure("ExampleStructure1",
{
   SHARED:
   {
      PUBLIC:
      {
         VARS:
         {
            "sharedPublicVar": "I am the structure's sharedPublicVar"
         },
         FUNCTIONS:
         {
            "sharedPublicFunction": function(pExampleStructure1)
            {
               //   Accessing private members
               console.log(this.O(pExampleStructure1).privateVar);

               //   And shared private members
               console.log(this.O(pExampleStructure1).sharedPrivateVar);

               //   And also shared publics,
               console.log(this.O(pExampleStructure1).sharedPublicVar);
               //   but never do this, instead do,
               console.log(pExampleStructure1.sharedPublicVar);


               //   Like 'this' in the previous section, 'O' must never be
               //      passed around, but this also applies to the return
               //      of 'O' which is another 'this'. For example, instead
               //      of returning this.O(pExampleStructure1) to return the
               //      instance pExampleStructure1, do the following
               return this.O(pExampleStructure1).THIS;
            }
         }
      },
      PRIVATE:
      {
         VARS:
         {
            "sharedPrivateVar": "I am the structure's sharedPrivateVar"
         }
      }
   },
   PRIVATE:
   {
      VARS:
      {
         "privateVar": "ExampleStructure1::privateVar"
      }
   }
});
crx_registerStructure("ExampleStructure2",
{
   INHERITS: ["ExampleStructure1"],
   SHARED:
   {
      PUBLIC:
      {
         VARS:
         {
            "sharedPublicVar": "I am the structure's sharedPublicVar (2)"
         },
         FUNCTIONS:
         {
            "test": function(pExampleStructre2)
            {
               this.sharedPublicFunction(pExampleStructre2);
            }
         }
      }
   }
});

var instance = crx_new("ExampleStructure2");

instance.test(crx_new("ExampleStructure2"));
ExampleStructure1::privateVar
I am the structure's sharedPrivateVar
I am the structure's sharedPublicVar (2)
I am the structure's sharedPublicVar (2)
JS (Verbose)
crx_registerStructure("ExampleStructure1",
{
   "VERBOSE": 1,
   "shared public var sharedPublicVar": "I am the structure's sharedPublicVar",
   "shared public function sharedPublicFunction": function(pExampleStructure1)
   {
      //   Accessing private members
      console.log(this.O(pExampleStructure1).privateVar);

      //   And shared private members
      console.log(this.O(pExampleStructure1).sharedPrivateVar);

      //   And also publics,
      console.log(this.O(pExampleStructure1).sharedPublicVar);
      //   but never do this, instead do,
      console.log(pExampleStructure1.sharedPublicVar);


      //   Like 'this' in the previous section, 'O' must never be
      //      passed around, but this also applies to the return
      //      of 'O' which is another 'this'. For example, instead
      //      of returning this.O(pExampleStructure1) to return the
      //      instance pExampleStructure1, do the following
      return this.O(pExampleStructure1).THIS;
   },
   "shared private var sharedPrivateVar": "I am the structure's sharedPrivateVar",
   "private var privateVar": "ExampleStructure1::privateVar"
});
crx_registerStructure("ExampleStructure2",
{
   "VERBOSE": 1,
   "inherits": ["ExampleStructure1"],
   "shared public var sharedPublicVar": "I am the structure's sharedPublicVar (2)",
   "shared public function test": function(pExampleStructre2)
   {
      this.sharedPublicFunction(pExampleStructre2);
   }
});

var instance = crx_new("ExampleStructure2");

instance.test(crx_new("ExampleStructure2"));
ExampleStructure1::privateVar
I am the structure's sharedPrivateVar
I am the structure's sharedPublicVar (2)
I am the structure's sharedPublicVar (2)