Chapter 8. Functions


A function is a block of JavaScript code that is defined once but may be invoked, or executed, any number of times. Functions may have parameters, or argumentslocal variables whose value is specified when the function is invoked. Functions often use these arguments to compute a return value that becomes the value of the function-invocation expression. When a function is invoked on an object, the function is called a method, and the object on which it is invoked is passed as an implicit argument of the function. You may already be familiar with the concept of a function under a name such as subroutine or procedure.

This chapter focuses on defining and invoking your own JavaScript functions. It is important to remember that JavaScript supports quite a few built-in functions, such as eval( ), parseInt(), and the sort() method of the Array class. Client-side JavaScript defines others, such as document.write() and alert(). Built-in functions in JavaScript can be used in exactly the same ways as user-defined functions. You can find more information about the built-in functions mentioned here in Parts III and IV of this book.

Functions and objects are intertwined in JavaScript. For this reason, I'll defer discussion of some features of functions until Chapter 9.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net