Functions |
|
A function is task that must be performed to complete the flow of an application. JScript .NET considers a function on three fronts. In JScript, you can use a function to create a tradition task known as function in two categories. A function can also be used to create an object.
In traditional programming, there are two types of functions: those that return a value and those that don't. Regardless of the type, in JScript, to create a function, you start with the function keyword followed by a name. To specify that this is a function and not a normal variable, the name of the function is followed by parentheses. Because a function is a task, its job is described between an opening and a curly brackets ( "{" and "}") typed after the parentheses of the function. Here is an example: function Welcome() { } The section between the curly brackets is referred to as the body of the function. In this section, you type what the function is supposed to do. The most basic type of function you can create is meant to perform a task but doesn't produce a value. In C/C++, C#, and related languages, such a function is referred to as void. When creating this type of function, simply describe the desired behavior of the function in its body. For example, you can use the function to display a message. Here is an example: function Welcome() { print("Welcome to the Wonderful World of JScript .NET"); }
There are two categories of functions you will use in your programs: the functions that were supplied to you through the JScript .NET compiler and those you create. Regardless of how you get a function, to use it, you must know the function and what it does. Using a function is also referred to as calling it. The most basic way to call a function consists of writing its name, followed by its parentheses, followed by a semi-colon. Here is an example: function Welcome() { print("Welcome to the Wonderful World of JScript .NET"); } Welcome();
|
|
||
Previous | Copyright © 2004 FunctionX, Inc. | Next |
|