powered by Authenteo
by Xucia  

Learn more

Persistent Objects

Persistent objects can have transient and persistent properties. Transient properties are just normal JavaScript properties that are accessed and modified with normal JavaScript syntax but they are not persisted. Persistent properties are accessed and modified by simply prefixing the property with the pound/hash symbol. For example:

            obj.prop1 = obj.prop2
          

This statement retrieves the property value of the persistent property ?prop2? and sets the value into the persistent property ?prop1?.

A persistent property can be set to a primitive (string, number, or Boolean) a primitive class (string, number, or boolean) or a persistent object (a simple object, list, or function). A persistent property can not be set to a non-persistent object. If a persistent property value is a primitive value. When the property is accessed (through get or persistent notation access) a primitive wrapper class will be returned (string, number, or Boolean) with has a property named parent that refers to the parent persistent object.

Another technique for accessing the persistent properties is to use getters and setters. In order for this to work you must enable the "makeGettersAndSetters" option in the settings in the settings in the admin explorer. Accessing a property with a getter is done calling a function with the name of the property with first letter capitalized and prepared with get. Setters work the same way.

So we could rewrite the previous example

            obj.setProp1(obj.getProp2());
          

However, to use the setter method this persistent property must already exist. Note that enabling setters and getters is a performance hit, so the # notation is the recommended technique for accessing persistent properties.

You can also write your own custom getter of setter function by simply writing a function with the appropriate property name getProp1() or setProp (value). This function will be called for when the property is accessed by a getter call or a # notation call.

For example:

            obj.getProp1 = function(){return5;};
          
            var test = obj.prop1;
          

If this is executed the test variable will be set to 5.

Another way to access Properties is by calling the get or set function. The syntax is:

            get(propertyname)
          
            set(propertyname, value)
          

The # notation is actually a compile time macro that is converted to a get or set function. The makeGettersAndSetters in the settings does not need to be enabled for this function to work. These functions can also be overridden for persistent objects.

Persistent fields can also be accessed with variable field names as you would with the bracket operator in JavaScript by prepending the opening bracket with a #. For example you can access a persistent property like this:

            var propName=?prop1?;
          
            value=obj[propName];
          

would equivalent to writing:

            value=obj.prop1;
          

You may use this notation for setting variable named persistent properties as well. For example:

            obj[propName]=value;
          

Persistent List Object

In addition to normal persistent objects that are string keyed properties, Authenteo also supports persistent list objects, or arrays that are accessed by index number. Persistent list object indexed entries should be accessed with the same syntax as a variable name property access. To access the entry number 5 in a persistent list:

            value=list[5];
          

You can also access the array entries with get or item function call. The following should behave the same:

            value=list.get(5);
          

or

            value=list.item(5);
          

To access the length or size of the list, use the persistent length property. The following code is an example of a for loop through a persistent list:

            for(var i=0;i < list.length;i++)
          
            value=list[i];
            

For the API documentation on all the functions available for using persistent objects go here .

News

Authenteo 1.1 is available.

Firebug - Web Development Evolved Now with Firebug integration . Make changes to CSS and HTML with Firebug and save the changes

Check out press releases and the following articles on Authenteo:

Authenteo beta