Home / Advanced JavaScript Tutorial / Creating Robusts Functions

 

 

CodingForums
Having trouble with scripting? Visit our help forum to get the answers you need.

Jump to...
-Free JavaScripts
-JS tutorials
-JS Reference
-DHTML/CSS

-Free applets
-Web Tutorials
-Link to Us!

- CSS Drive
- JavaScript Menus
- PHP Resources
- Hotels & Vacations
- Java Online Casinos
- Web hosting Search
 


Red_CurlyC035.gif (285 bytes) Creating robust functions

With the help of the arguments array, in addition to a minor change when defining a function, we can create a function that accepts any number of parameters.

The first order of buisness is to define a robust function. A function as such looks exactly the same as a function with say, two or three parameters, only that the parameters are not explicitly specified.

function robust(){

}

Now that that's out of the way, the remaining work is to create a mechanism using the arguments array that dynamically retrieves all of the parameters that get passed in, so the remaining portion of the function can do its job with them. A simple for loop will do nicely:

function robust(){
for (i=0;i<robust.arguments.length;i++)
//do whatever
}

-Tutorial introduction
-Quick overview of a "normal" function
-The limitations of a normal function
-The arguments array- the secret to robustness
-Creating robust functions
-Examples

Examples Small4.gif (1046 bytes)


http://javascriptkit.com
Copyright © 1997-2005 JavaScript Kit. NO PART may be reproduced without author's permission.