SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing variable-length argument list from one function to another

    Given the following code:

    Code:
    var xf2;
    function f1()
    {
      if (document.createElement && document.body && document.body.appendChild) {
        xf2 = new f2(arguments[]);
      }
    }
    I am getting a syntax error in the "new" statement following the [].

    How do I pass the variable-length arguments list received by f1 on to f2?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just wanna pass the arguments length to f2? or all the arguments?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to pass all the arguments, exactly as they came into f1

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is simplest, but f2 has to take apart the single argument that is
    passed it as an object:
    function f1(){
    if(whatever is true)xf2=new f2(arguments)
    }
    function f2(arg){
    use arg as if it were arguments
    var L=arg.length;
    if arg[2];
    whatever
    }

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Confirmed it works.


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
  •