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.5 HASOWN

"HASOWN" is the equivilant of the built in hasOwnProperty function and is meant to be used for iteration on the structure members.

HASOWN(memberName, scopeFlags, typeFlags, isExclusive)
memberName
String
The member name.
scopeFlags
integer
The flag filters the members iterated over based on their access level. These are:

crxOop.HASOWN_SCOPE_SHARED_PUBLIC = 8 for members that are "shared public"
crxOop.HASOWN_SCOPE_SHARED_PRIVATE = 16 for members that are "shared private"
crxOop.HASOWN_SCOPE_PRIVATE = 32 for members that are "private"

Defaults to 8 (crxOop.HASOWN_SCOPE_SHARED_PUBLIC)
scopeFlags
integer
The flag filters the members based on their type. These are:

crxOop.HASOWN_TYPE_VAR = 1 for members that are variables
crxOop.HASOWN_TYPE_FUNCTION = 2 for members that are functions
crxOop.HASOWN_TYPE_FOREIGN = 4 for members that were not defined in the structure definition

Defaults to 1 (crxOop.HASOWN_TYPE_VAR)

Foreign members are members declared in the constructor, not in the class definition. Such declaration is highly discouraged, but allowed.
isExclusive
boolean
If true, selects only members belonging to the structure itself, which include those defined by the structure and those defined by the structure's ancestors. Otherwise, selects all memebers visible to the structure. Note that foreign members would not be selected if set to true.
Return
Object
true or false
Example
crx_registerStructure("MyStructure1",
{
   "VERBOSE": 1,
   "shared public var sharedPublicVar": "MyStructure1::sharedPublicVar",
   "shared public function sharedPublicFunction": function()
   {
      return "MyStructure1::sharedPublicFunction()";
   },
   "shared private var sharedPrivateVar": "MyStructure1::sharedPrivateVar",
   "shared private function sharedPrivateFunction": function()
   {
      return "MyStructure1::sharedPrivateFunction()";
   },
   "private var privateVar": "MyStructure1::privateVar",
   "shared public function test2": function()
   {
      console.log("---");
      console.log("---");
      console.log("Iterating over all variables and functions of current structure (MyStructure1)");
      console.log("---");
      
      for(tKey in this)
      {
         if(this.HASOWN(tKey, crxOop.HASOWN_SCOPE_SHARED_PUBLIC | crxOop.HASOWN_SCOPE_SHARED_PRIVATE |
               crxOop.HASOWN_SCOPE_PRIVATE, crxOop.HASOWN_TYPE_VAR | crxOop.HASOWN_TYPE_FUNCTION, true))
         {
            console.log(tKey);
         }
      }
   }
});
crx_registerStructure("MyStructure2",
{
   "VERBOSE": 1,
   "inherits": ["MyStructure1"],
   "shared public var sharedPublicVar2": "MyStructure2::sharedPublicVar2",
   "shared public function sharedPublicFunction": function()
   {
      return "MyStructure2::sharedPublicFunction()";
   },
   "shared private var sharedPrivateVar": "MyStructure2::sharedPrivateVar",
   "shared public function test1": function()
   {
      console.log("Iterating over shared public and shared private variables and functions");
      console.log("---");

      for(tKey in this)
      {
         if(this.HASOWN(tKey, crxOop.HASOWN_SCOPE_SHARED_PUBLIC | crxOop.HASOWN_SCOPE_SHARED_PRIVATE,
               crxOop.HASOWN_TYPE_VAR | crxOop.HASOWN_TYPE_FUNCTION))
         {
            console.log(tKey);
         }
      }

      console.log("---");
      console.log("---");
      console.log("Iterating over shared private and private variables");
      console.log("---");
      
      for(tKey in this)
      {
         if(this.HASOWN(tKey, crxOop.HASOWN_SCOPE_SHARED_PRIVATE | crxOop.HASOWN_SCOPE_PRIVATE,
               crxOop.HASOWN_TYPE_VAR))
         {
            console.log(tKey);
         }
      }

      console.log("---");
      console.log("---");
      console.log("Iterating over all variables and functions of current structure (MyStructure2)");
      console.log("---");
      
      for(tKey in this)
      {
         if(this.HASOWN(tKey, crxOop.HASOWN_SCOPE_SHARED_PUBLIC | crxOop.HASOWN_SCOPE_SHARED_PRIVATE |
               crxOop.HASOWN_SCOPE_PRIVATE, crxOop.HASOWN_TYPE_VAR | crxOop.HASOWN_TYPE_FUNCTION, true))
         {
            console.log(tKey);
         }
      }
   }
});

var gMyStructure = crx_new("MyStructure2");

gMyStructure.test1();
gMyStructure.test2();
Iterating over shared public and shared private variables and functions
---
sharedPrivateFunction
sharedPublicVar
sharedPublicVar2
sharedPrivateVar
sharedPublicFunction
test2
test1
---
---
Iterating over shared private and private variables
---
sharedPrivateVar
---
---
Iterating over all variables and functions of current structure (MyStructure2)
---
sharedPrivateFunction
sharedPublicVar
sharedPublicVar2
sharedPrivateVar
sharedPublicFunction
test2
test1
---
---
Iterating over all variables and functions of current structure (MyStructure1)
---
privateVar
sharedPrivateFunction
sharedPublicVar
sharedPrivateVar
sharedPublicFunction
test2