Property Functions

AwesomeScript makes heavy use of what’s called Property Functions. In most OOP languages, you are encouraged to create wrapping functions to get and set class members. However, use getProperty(), setProperty() is incredibly cumbersome and boring to write. Instead, AwesomeScript combines getters and setters in the same function.


To put it simple, Property() and Property(value). When you have a property on an object or element, calling the property function without parameters (except for the Style property) will return the current value. Calling the function with a parameter will set the current value. Below is an example:

function toggle(){
    var m = $Div("myDiv");

We retrieve the div element with the id "myDiv" and we set it’s Collapsed state to the negated value of it’s current state.


When you are setting a value with most property functions, the returning value is the calling object. This allows you to set multiple properties in  a single line.

function newAnchor(url){
    return new Anchor().Text(url).Href(url).Target("_blank");

This is also done on some function calls. In order to determine which property functions and normal functions allow chaining, note the Intellisense. The vsdoc included will determine if you are getting or setting a property and will bring up proper support for chaining if applicable. Also, in the documentation, if the return value of a property or function is of the same type of the caller, then this indicates chaining is possible.


Fields vs Property Functions

A field is a piece of information that has no direct effects when modified. An example is the Enabled field of a Delegate. Enabling/disabling a delegate prevents it from firing on events, but when setting it, there is no immediate effect on the parent object. However, property functions cause other code to execute, such as the Enabled property of an Anchor, setting this will change it’s opacity level and prevent href activation (or enable it).


Fields and properties are distinguished through out the documentation. Property functions look just like functions, but their name and return values are distinguishable in the documentation and Intellisense.


Last edited Feb 16, 2011 at 6:14 PM by dahrkdaiz, version 1


No comments yet.