On Wed, Mar 16, 2011 at 12:14 PM, Rob Griffiths <r...@bytespider.eu> wrote:
>
>> Length should return the value of the last index + 1, so in that case
>> length will return 8
>
> I knew I should have checked before stating that.
>
> --
> Rob Griffiths
> http://bytespider.eu
> @bytespider
> https://github.com/bytespider
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/jsmentors@jsmentors.com/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com
>

I use the following to convert/concat NodeList to Array:

  // concat elements to data array
  concatList =
    function(data, elements) {
      var i = -1, element;
      if (data.length === 0 && Array.slice)
        return Array.slice(elements);
      while ((element = elements[++i]))
        data[data.length] = element;
      return data;
    },

On older browsers this was the fastest "loop" among many browsers at
the time I tested it and on newer browsers this is not used/necessary.

I am not sure using Firefox "Array.slice" shortcut when "data" array
is empty is worth it (nowadays) so the bare bone JS should be this:

  // concat elements to data array
  concatList =
    function(data, elements) {
      var i = -1, element;
      while ((element = elements[++i]))
        data[data.length] = element;
      return data;
    },

At that time another interesting thing I observed was that Webkit
based browser were also faster to access DOM element in the ancient
way using the "nodelist.item(n)" notation (really much faster).

The point is performances are improving at a fast pace in every
browser engine so small speed improvements like these are becoming
less and less relevant, it is still a funny exercise though :)

--
Diego

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to