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.3.6 Public and Private Static Functions

There are three types of class functions. In this section we discuss the third type, which is static functions. Like static variables, static functions are shared functions among all instances of a particular class. Both public and private accessors are supported. Unlike C++, which has the scope operator "::" to access static variables and static functions, Javascript has no such thing, and CrxOop provides the global keyword 'crx_static', and the class keyword 'STATIC' to access those functions. However, unlike STATIC, crx_static can only be used to access public static functions, not private ones. Inside static funtions, you can also use 'this.STATIC' to access private static functions. Hence, Inside your instance functions, instance virtual functions and static functions, use 'this.STATIC.somePublicOrPrivateStaticFunction()', and elsewhere use crx_static.

Note that inside static functions, 'this', 'this.O', the return of 'this.O()', and 'this.STATIC', must never be returned from the static functions, or passed to other functions as parameters.

Example: Public and Private Static Functions
JS (Tree)
crx_registerClass("ExampleClass",
{
   PUBLIC:
   {
      STATIC:
      {
         VARS:
         {
            "publicStaticVar": 1
         },
         FUNCTIONS:
         {
            "test": function(pExampleClass)
            {
               //   Notice the usage of this.O to access the private variables of an instance
               //      from the same class
               console.log(this.STATIC.publicStaticVar + "," +
                     this.STATIC.privateStaticVar + "," +
                     this.O(pExampleClass).privateVar);

               //   Could have also used crx_static to access a public static member
               //      from the same class
               console.log(crx_static("ExampleClass").publicStaticVar + "," +
                     this.STATIC.privateStaticVar + "," +
                     this.O(pExampleClass).privateVar);
            }
         }
      }
   },
   PRIVATE:
   {
      VARS:
      {
         "privateVar": 5
      },
      STATIC:
      {
         VARS:
         {
            "privateStaticVar": 3
         }
      }
   }
});
var instance = crx_new("ExampleClass");

crx_static("ExampleClass").test(instance);
1,3,5
1,3,5
JS (Verbose)
crx_registerClass("ExampleClass",
{
   "VERBOSE": 1,
   "public static var publicStaticVar": 1,
   "public static function test": function(pExampleClass)
   {
      //   Notice the usage of this.O to access the private variables of an instance
      //      from the same class
      console.log(this.STATIC.publicStaticVar + "," +
            this.STATIC.privateStaticVar + "," +
            this.O(pExampleClass).privateVar);

      //   Could have also used crx_static to access a public static member
      //      from the same class
      console.log(crx_static("ExampleClass").publicStaticVar + "," +
            this.STATIC.privateStaticVar + "," +
            this.O(pExampleClass).privateVar);
   },
   "private var privateVar": 5,
   "private static var privateStaticVar": 3
});
var instance = crx_new("ExampleClass");

crx_static("ExampleClass").test(instance);
1,3,5
1,3,5