473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Different amount of variables in same function

2
I would like to create a function that is variable in the number of variables it processes.

Example
function myFunction(myVariableVar){
// Loop through the myVariableVar list and do the function
}


So when the function is used on different pages like this
3 variables: myFunction(var1,varb,varc);
or more variables: myFunction(var1,varb,varc,var4,vard,var7,var5,var9 );

bearing in mind that the vars used will be valid elementIDs or elementNames
I would like help to start the function ie, the "loop command" and i will add the function. If this is not too hard for you script gurus.

Thankyou
Apr 19 '07 #1
1 982
mrhoo
428 256MB
/*
(Moderator: I Edited the try block- my previous post may be deleted)

This is a an Array method that runs the same function
on each of its members, and returns an array of the results.
I include an example function to test- you can adapt it for your purpose.

**************************/

Expand|Select|Wrap|Line Numbers
  1. Array.prototype.forAll= function(fun,args){
  2.     var L= this.length, A= [], tem;
  3.     for(var i= 0; i< L; i++){
  4.         try{
  5.             if(args===true)tem= fun(this[i]);
  6.             else tem= fun.apply(this[i],args);
  7.         }
  8.         catch(er){
  9.             tem= null;
  10.         }
  11.         if(boo=== true && !tem) continue;
  12.         A.push(tem);
  13.     }
  14.     return A;
  15. }
// ************************** test function

Expand|Select|Wrap|Line Numbers
  1. var fun= function(){
  2.     return ('\n'+i++) +'. '+this.tagName+
  3.     '-  descendents: '+ this.getElementsByTagName('*').length;
  4. }
  5. function collect(hoo){
  6.     var collection= [], who,i=0;
  7.     var L = hoo.length;
  8.     if (hoo.length) while(i< L) collection.push(hoo[i++]);
  9.     else if (typeof hoo == "object"){
  10.         for (var o in hoo) if(hoo.hasOwnProperty(o)) collection.push(hoo[o]);
  11.     }
  12.     return collection;
  13. }
  14. var A=document.body.getElementsByTagName('*');
  15. A=collect(A);
  16. var i=1;

// ************************** And the function command:

A= A.forAll(fun)
alert(A.slice(0,25));
Apr 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Sebastian Kerekes | last post by:
Greetings, I'm developing an application that supports multiple languages. In my XSL I use variables to place the text where it belongs to. At the top of the document I include those variables -...
10
by: ypjofficial | last post by:
Hello All, since the programs' stack is shared among all the function inside the program, I was just doing some R&D to see whether the same stack space is used for the variables inside the...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.