Page 2 of 2
The function evaluation operator
To evaluate a function you use the () operator:
which executes the functionobject to its left and evaluates to the result that the function returns.
Notice that you can apply the () operator to a function object no matter how you choose to retrieve it so you can use the property notation to make it look like an object method:
or you can use array notation which makes the method call look very odd:
It doesn't matter how odd it looks as the () operator always evaluates the function object to its left and returns the result of the function as its value.
Now we need to look at the special case of integer keys. As an alternative to string keys you can use integer keys but if you do use a string key you cannot refer to the value using its ordinal position in the array. For example if you define the array as:
That is if you define:
you can retrieve the function using
So apart from not being able to use property syntax integer keys are no different. However they look as if they should be different. In particular an associative array with integer keys looks like a standard indexed array - but it isn't. For example, if we redefine array:
then you can call the function using:
If you want to use an associative array use an Object.
If you want to use an indexed array use Array.
That is don't use