Results 1 to 7 of 7

Thread: Array class getting a remove function from the adapters

  1. #1
    Ext User
    Join Date
    Jun 2007
    Posts
    15
    Vote Rating
    0
      0  

    Default Array class getting a remove function from the adapters

    Using version 1.0.1a, tested with prototype and yui adapters.

    I'm finding that new Array's are not empty. They contain a function called remove. This seems to be introduced by the adapter classes. Note this example.

    PHP Code:
    <html>
    <
    head>
            <
    script type='text/javascript' src='/ext/adapter/prototype/ext-prototype-adapter.js'>
            
    </script>
    </head>

    <body onload="testArray();">

    <div id="mydiv"></div>

    </body>
    </html>
    <script>
       function testArray(){
          var a = new Array();
          a.push("dummy element");
          var s = "";
          for(var i in a){
              s += (typeof(a[i]) + "<br>");
           }
          document.getElementById("mydiv").innerHTML = s;
       }
    </script> 
    With the adapter included the results are
    PHP Code:
    string
    function 
    With the adapter not included the results are
    PHP Code:
    string 
    Is this a known issue? Is there a fix?

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956
    Vote Rating
    20
      0  

    Default

    It's not an element in the array, it's a function on the Array prototype. for(var key in obj) is not iterating the array, it's iterating the object.
    Jack Slocum
    Sencha Co-Founder, Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    52
    Vote Rating
    2
      0  

    Default

    Please don't remove remove(). I love that little function.

    As an alternative to for(x in y) you can use for(var x; x < y.length; x++), then you won't get the remove() function.

  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956
    Vote Rating
    20
      0  

    Default

    Don't worry we can't remove it, we use it as well.
    Jack Slocum
    Sencha Co-Founder, Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Posts
    29
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by exo View Post
    Please don't remove remove(). I love that little function.

    As an alternative to for(x in y) you can use for(var x; x < y.length; x++), then you won't get the remove() function.
    I'm using this syntax too, but for a lookup table with the key on the record's id it's not reliable. Fortunaletly Jack has posted a simple workaround so the that "foreach" can be used too.

    http://extjs.com/forum/showthread.ph...r+array+object
    Check out post 5. In my case I had to add a comparison to 'undefined' as my keys map database ids. It seems to work fine for me.

    Code:
    Ext.each(grids, function(grid, index, grids){
      if (typeof grid != 'function' && typeof grid != 'undefined'){
        grid.getSelectionModel().clearSelections();
      }
    }, this);

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    0
      0  

    Default

    There are numerous discussions on the web regarding the differences between iterating over an array with for(x in y) vs for(var x; x < y.length; x++), and why you shouldn't use the former unless you understand what's going on.

  7. #7
    Ext User
    Join Date
    Jun 2007
    Posts
    15
    Vote Rating
    0
      0  

    Default

    Thanks

    This works for me

Posting Permissions

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