contents   index   previous   next



Function scope

 

Functions are all global in scope, much like global variables. A function may not be declared within another function so that its scope is merely within a certain function or section of a script. All functions may be called from anywhere in a script. If it is helpful, think of functions as methods of the global object. The following two code fragments do exactly the same thing. The first calls a function, SumTwo(), as a function, and the second calls SumTwo() as a method of the global object.

 

// fragment one

function SumTwo(a, b)

{

   return a + b

}

 

Screen.writeln(SumTwo(3, 4))

 

// fragment two

function SumTwo(a, b)

{

   return a + b

}

 

Screen.writeln(global.SumTwo(3, 4))

 


Data types