In addition to operators and primary expressions, Sling also include a set of "compound primary expressions", as follows:

Member Access Expressions

Using the "." operator, several expressions can be concatenated to each other, indicating "access to members". The syntax is as follows:

<expression 1>.<expression 2>

The above indicates accessing the member "<expression 2>" or "<expression 1>".

Function Call Expressions

Function call expressions are expressed by adding the opening parenthesis character "(" after an expression, followed by a comma-separated list of parameter expressions to include in the function call, if any, followed by the closing parenthesis:

myFunction()
myFunction(10)
myFunction(100, "string")

Subscript Expressions

Subscript expressions are expressed by adding the opening square bracket character "[" after an expression, followed by an expression denoting the subscript "index" or value, followed by the closing square bracket. Subscripts can be used with array, vector, map or buffer data types to access elements in specific indexes or locations within the data structure.

var myArray = [ 1, 2, 3, 4 ]
var n = myArray[1] // n will be 2

OR

var myMap = {
	"first" : "First Value",
	"second" : "Second Value"
}
PRINT myMap["second"] // prints "Second Value"

Twitter Facebook LinkedIn Youtube Slideshare Github