Linux web host - 1095Chapter 41 .Functions and Custom Objects the statements
1095Chapter 41 .Functions and Custom Objects the statements that execute whenever the function is called. Separate each JavaScript statement with a semicolon, and enclose the entire sequence of statements inside quotes, as in the following: var willItFit = new Function( width , height , var sx = screen.availWidth; var sy = screen.availHeight; return (sx >= width && sy >= height) ) The willItFit() function takes two parameters; the body of the function defines two local variables (sx and sy) and then returns a Boolean value of true if the incoming parameters are smaller than the local variables. In traditional form, this function is defined as follows: function willItFit(width, height) { var sx = screen.availWidth var sy = screen.availHeight return (sx >= width && sy >= height) } Once this function exists in the browser s memory, you can invoke it like any other function: if (willItFit(400,500)) { statements to load image } One last function creation format is available in NN4+. This advanced technique, called a lambda expression, provides a shortcut for creating a reference to an anonymous function (truly anonymous because the function has no name that you can reference later). The common application of this technique is to assign function references to event handlers when the NN event object also must be passed. The following is an example of how to assign an anonymous function to an onChange event handler for a form control: document.forms[0].age.onchange = function(event) {isNumber(document.forms[0].age)} Nesting functions NN4+ and IE4+ also provide for nesting functions inside one another. In all prior scripting, each function definition is defined at the global level whereby every function is exposed and available to all other scripting. With nested functions, you can encapsulate the exposure of a function inside another and make that nested function private to the enclosing function. Of course I don t recommend reusing names in this fashion, but you can create nested functions with the same name inside multiple global level functions, as the following skeletal structure shows: function outerA() { statements function innerA() { statements } statements } functionObject
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.