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.6 STATIC

'STATIC' is used to access the static members of a class. Internaly, on class instances only, two 'STATIC's exist, one in the private memory sector, and one in the public memory sector, and they are accessed using "this.STATIC" and "this.THIS.STATIC". Unlike "this.THIS.STATIC", "this.STATIC" is unsafe to pass to functions as parameters or from functions as returns.

In static functions, only "this.STATIC" exists, and it is also unsafe to pass to functions as parameters or from functions as returns.

JS (Tree)
crx_registerClass("ExampleClass",
{
   PUBLIC:
   {
      CONSTS:
      {
         "publicConstant": 1
      },
      STATIC:
      {
         VARS:
         {
            "publicStaticVar": 4
         },
         FUNCTIONS:
         {
            "test2": function()
            {
               //   Accessing a public static member and a public constant
               console.log(this.STATIC.publicStaticVar);
               console.log(this.STATIC.publicConstant);
               //   and we could have done this
               console.log(crx_static("ExampleClass").publicStaticVar);
               console.log(crx_static("ExampleClass").publicConstant);

               //   Accessing a private static member and a private constant
               console.log(this.STATIC.privateStaticVar);
               console.log(this.STATIC.privateConstant);
               //   but unlike the public accessor case, the following
               //      will not work.
               console.log(crx_static("ExampleClass").privateStaticVar);
               console.log(crx_static("ExampleClass").privateConstant);
            }
         }
      },
      FUNCTIONS:
      {
         'test': function()
         {
            //   Accessing a public static member and a public constant
            console.log(this.STATIC.publicStaticVar);
            console.log(this.STATIC.publicConstant);
            //   and we could have done this
            console.log(crx_static("ExampleClass").publicStaticVar);
            console.log(crx_static("ExampleClass").publicConstant);

            //   Accessing a private static member and a private constant
            console.log(this.STATIC.privateStaticVar);
            console.log(this.STATIC.privateConstant);
            //   but unlike the public accessor case, the following
            //      will not work.
            console.log(crx_static("ExampleClass").privateStaticVar);
            console.log(crx_static("ExampleClass").privateConstant);
         }
      }
   },
   PRIVATE:
   {
      CONSTS:
      {
         "privateConstant": 2
      },
      STATIC:
      {
         VARS:
         {
            "privateStaticVar": 5
         }
      }
   }
});

var instance = crx_new("ExampleClass");

instance.test();
console.log('------------------');
console.log('DOING TESTS FROM WITHIN A STATIC FUNCTION');
crx_static('ExampleClass').test2();
4
1
4
1
5
2
undefined
undefined
------------------
DOING TESTS FROM WITHIN A STATIC FUNCTION
4
1
4
1
5
2
undefined
undefined
JS (Verbose)
crx_registerClass("ExampleClass",
{
   "VERBOSE": 1,
   "public const publicConstant": 1,
   "public static var publicStaticVar": 4,
   "public static function test2": function()
   {
      //   Accessing a public static member and a public constant
      console.log(this.STATIC.publicStaticVar);
      console.log(this.STATIC.publicConstant);
      //   and we could have done this
      console.log(crx_static("ExampleClass").publicStaticVar);
      console.log(crx_static("ExampleClass").publicConstant);

      //   Accessing a private static member and a private constant
      console.log(this.STATIC.privateStaticVar);
      console.log(this.STATIC.privateConstant);
      //   but unlike the public accessor case, the following
      //      will not work.
      console.log(crx_static("ExampleClass").privateStaticVar);
      console.log(crx_static("ExampleClass").privateConstant);
   },
   "public function test": function()
   {
      //   Accessing a public static member and a public constant
      console.log(this.STATIC.publicStaticVar);
      console.log(this.STATIC.publicConstant);
      //   and we could have done this
      console.log(crx_static("ExampleClass").publicStaticVar);
      console.log(crx_static("ExampleClass").publicConstant);

      //   Accessing a private static member and a private constant
      console.log(this.STATIC.privateStaticVar);
      console.log(this.STATIC.privateConstant);
      //   but unlike the public accessor case, the following
      //      will not work.
      console.log(crx_static("ExampleClass").privateStaticVar);
      console.log(crx_static("ExampleClass").privateConstant);
   },
   "private const privateConstant": 2,
   "private static var privateStaticVar": 5
});

var instance = crx_new("ExampleClass");

instance.test();
console.log('------------------');
console.log('DOING TESTS FROM WITHIN A STATIC FUNCTION');
crx_static('ExampleClass').test2();
4
1
4
1
5
2
undefined
undefined
------------------
DOING TESTS FROM WITHIN A STATIC FUNCTION
4
1
4
1
5
2
undefined
undefined