Share this Page URL

Chapter 22. Using Scripts in Your Web Pa... > Object-Oriented Technology - Pg. 386

Using Scripts in Your Web Pages 386 Subroutines in JavaScript are simply functions that do not return values. Therefore, the func- tion command is all that is required to define a block of reusable code within an application or Web page. Example functions defined in JavaScript could be as follows: Function SquareRoot(number as int){ // Code to determine square-root of a number Return result; } Function OpenDocument(file as string){ // Code to open filename passed to function } Object-Oriented Technology Computers improved with the advent of operating systems that use a graphical user interface such as those found on the Macintosh and Windows machines; with that improvement there developed a need for a better programming model. In the past, developers could simply write a series of com- puter program statements that would be executed sequentially. Even with functions and subroutines defined, the program executed from a beginning and ended at some point. These starting and ending points became less obvious in the world of Windows-based operating systems because the user interface opened the possibility for programs to react based on user input. For example, in the past you could run a DOS-based application that performed one function based on a series of parameters provided to it, such as copying a file from one drive to another. This copy program had a start and a finish--and no user interaction between those two points. However, even a somewhat simple application (such as Notepad in Windows) suddenly opens a large amount of user interactivity. The user can click menus to open files, close files, exit the program, search within