Function Scope

Functions are accessible within the scope in which they are created, unless they are explicitly defined in a different scope. Thus, a function which is defined in the OnClick() event handler of a command button can only be called by other statements in that event handler.

Example—Two command buttons in a dashboard section:

// MyButton
function square(value)
{
return value*value;
}
Alert (‘’The square of 3 equals ‘’+ square(3))


// YourButton
var retVal = square(3) 
// generates a runtime error
Alert (‘’The square of 3 equals ‘’+ retVal)

The square function is only visible in the context of MyButton. As a result, a call to the square function from YourButton generates a runtime error.