Function takes parameters in any order

[Total: 0    Average: 0/5]

This examples shows how to have a function accept arguements in any order in which the caller wants to put them.

Body Code:

<a href='javascript:x("a=1","b=2","c=3")'>a-b-c</a><BR>
<a href='javascript:x("b=1","a=2","c=3")'>b-a-c</a><BR>

// parameters are called arguments
// This function takes in arguements and evaluates the variables
// as they are passed to this function.
function x() {
  for(var _p=0;_p< arguments.length;_p++) {
    eval("var "+arguments[_p]); // this declares them in the local scope only!

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *