Msn web hosting - 73Chapter 7Programming Fundamentals, Part IIclassification of routine exists

73Chapter 7Programming Fundamentals, Part IIclassification of routine exists for JavaScript. A function is capable of returning a value to thestatement that invoked it, but this is not a requirement. However, when a function doesreturn a value, the calling statement treats the function call like any expression plugging inthe returned value right where the function call is made. I will show some examples in amoment. Formal syntax for a function is as follows: function functionName( [parameter1]…[,parameterN] ) { statement[s] } Names you assign to functions have the same restrictions as names you assign to HTML ele- ments and variables. You should devise a name that succinctly describes what the functiondoes. I tend to use multiword names with the interCap (internally capitalized) format thatstart with a verb because functions are action items, even if they do nothing more than get orset a value. Another practice to keep in mind as you start to create functions is to keep the focus of eachfunction as narrow as possible. It is possible to generate functions that are literally hundredsof lines long. Such functions are usually difficult to maintain and debug. Chances are that youcan divide the long function into smaller, more tightly focused segments. Function parametersIn Chapter 5, you saw how an event handler invokes a function by calling the function byname. Any call to a function, including one that comes from another JavaScript statement, works the same way: a set of parentheses follows the function name. You also can define functions so they receive parameter values from the calling statement. Listing 7-1 shows a simple document that has a button whose onclickevent handler calls afunction while passing text data to the function. The text string in the event handler call is ina nested string a set of single quotes inside the double quotes required for the entire eventhandler attribute. Listing 7-1:Calling a Function from an Event Handler


Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services