SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    328
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to pass parameter to function with unequal arguments

    Hello,
    I know how to pass parameters between functions, but I want to pass around parameters between functions with unequal arguments like an example below:
    Code:
    function a(i) {
    	return(i);
    	c(i);
    }
    function b(j) {
    	return(j);
    	c(j);
    }
    function c(i,j) {
    	return(i+j);
    }
    How do I do that?
    Thank you,

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ketting00 View Post
    Code:
    function a(i) {
    	return(i);
    	c(i);
    }
    The return statement ends the execution of a function, so in the example above, c(i) is never executed.
    If you mean you want to pass variable numbers of parameters, then JavaScript allows that anyway.
    Of course where variable numbers of arguments are expected, the receiving function must check that parameters are not undefined prior to using them.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    328
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thank for your help,
    So you are suggesting that if there is only function a is working at the time, function c will do it job anyway. I want variable i from function a always the first argument in c and not j from function b.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •