This project is archived and is in readonly mode.

#1006 ✓resolved
digitarald

Unecpected behaviour from Array.erase on Elements

Reported by digitarald | September 15th, 2010 @ 07:23 AM | in 1.3.0 rc2 (closed)

On Element collections from getELements or getChildren, erase does not work as expected. This might be a side behaviour of a bigger bug in Elements or Slick.

Problem: Array.erase from Elements corrects the collection length but does not remove the element. Converting the collection with Array.from, fixes the problem. Same code works as expected in 1.2.

Example: http://jsfiddle.net/Jm4tx/1/

Comments and changes to this ticket

  • Tim Wienk

    Tim Wienk September 15th, 2010 @ 09:06 AM

    It seems to work as expected in Chrome. It seems that in Firefox (and perhaps other browsers?) the items are shifted correctly, the length is changed correctly, but the last item isn't removed.

    Example: http://jsfiddle.net/Jm4tx/3/

  • Christoph Pojer

    Christoph Pojer September 15th, 2010 @ 01:11 PM

    • Milestone set to 1.3.0 rc2
    • State changed from “new” to “open”
    • Assigned user changed from “Thomas Aylott” to “Valerio”
    • Milestone order changed from “768” to “0”

    I think this has to do with the change that Elements is now an Array-like Object instead of an Array.

  • Christoph Pojer

    Christoph Pojer September 15th, 2010 @ 01:28 PM

    @Harald

    can you confirm that this would fix it (just experimenting) - implement on Elements

    splice: (function(){
        var length = this.length;
        Array.prototype.splice.apply(this, arguments);
    
        for (var i = length; i >= this.length; i--)
            delete this[i];
    
        return this;
    }).protect()
    

    I am not sure at which point it is better to just revert Elements to an Array again, but if this is the only fix we need, it should be a viable solution.

  • digitarald

    digitarald September 15th, 2010 @ 01:55 PM

    Maybe without for loop:

    splice: (function(){
        var length = this.length - 1,
            i = Array.prototype.splice.apply(this, arguments).length;
    
        while (i--) delete this[length - i];
    
        return this;
    }).protect()
    

    And as we just chatted, Array specs should simply run against Elements too to verify that both Types work the same.

  • Christoph Pojer

    Christoph Pojer September 15th, 2010 @ 07:14 PM

    • State changed from “open” to “resolved”
    • Assigned user changed from “Valerio” to “Christoph Pojer”

    Thanks for the bug report. Apparently this is a bug in some engines :) Resolved in 1.3

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages