SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)

    Manipulating arguments array

    I can't figure out why this won't work. Is there a rule or something that I am unaware of where it isn't possible to manipulate the arguments array? I'm trying to build a linked data structure but, need to remove the first element of the arguments passed and this isn't working. Any help is appreciated- thanks.

    Code:
    function employee() {
      arguments.shift();
      alert(arguments);
      
      /*this.name = arguments[0];
      if(arguments.length == 1) return alert('finished creating hierarchy');
      arguments.shift();
      this.supervisor = new employee(arguments);*/
    }
    
    
    
    var business = new employee('john','sandy','mandy','tim');

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that the argument array is readonly.

    I managed to get around by creating a new array from the argument array:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css" media="screen" />
            <style type="text/css"></style>
            <script type="text/javascript">
                function employee() {
                    var arr = buildArgumentArray(arguments);
                    alert(arr.length);
                    if(arr.shift)
                        alert(arr.shift());
                }
                function buildArgumentArray(arguments) {
                    var arr = new Array(arguments.length);
                    for(var i = 0; i < arguments.length; i++)
                        arr[i] = arguments[i];
                    return arr;
                }
                window.onload = function() {
                    new employee();
                    new employee('test');
                    new employee('test', 'test');
                    new employee('test', 'test', 'test', 'test');
                }
            </script>
        </head>
        <body>
            
            
    
        </body>
    </html>


  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    Alright, that is what I was thinking and the solution I was going to implement. I was just checking if it might have been for a reason I could get around.

    thanks


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
  •