Yes

-Aaron

Sorry for any typos. Big fingers , tiny buttons.

On Dec 15, 2009, at 5:26 AM, Roman Land <[email protected]> wrote:

Steve, your right, wrong choice of words, I meant defined indexes :)

Ah, love being right! =p

Thanks Ryan, but the first element is at index 1 by design, thats the way it should work.

Thanks Aaron! BTW, didnt check the code but this covers $each as well? (99.9% that it would but just checking)


On Tue, Dec 15, 2009 at 7:05 AM, Aaron Newton <[email protected]> wrote:
https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array/ForEach

It would appear that our implementation of forEach is, indeed, incorrect.


-Aaron

Sorry for any typos. Big fingers , tiny buttons.

On Dec 14, 2009, at 8:56 PM, Roman Land <[email protected]> wrote:

For one, Firefox doesnt include it, neither does Chrome, but IE does, you could be right, and you could be wrong, it really depends on who is implementing the foreach loop, either way I am with FF Chrome etc, foreach should iterate over existing elements only!

On Tue, Dec 15, 2009 at 3:48 AM, Steve Onnis <[email protected]> wrote: even though it may be empty or null, the array position is still there so why wouldnt it be included in the each loop?

From: Roman Land [mailto:[email protected]]
Sent: Tuesday, 15 December 2009 12:42 PM

To: [email protected]
Subject: Re: [Moo] Found a very annoying bug..

if you read the literal function name - foreach - makes you expect they function to run over existing array banks only. That is the only part I am arguing about, I dont see how is my array "dirty" for not having an element in position 0.

On Tue, Dec 15, 2009 at 3:17 AM, Steve Onnis <[email protected]> wrote:
i would disagree

if you say "hey here is an array, can you loop over it for me?" then it is doing what you ask it to do...its not the functions fault that you hand it dirty data. its up to you as a programmer to deal with the data correctly.

From: Roman Land [mailto:[email protected]]
Sent: Tuesday, 15 December 2009 11:53 AM

To: [email protected]
Subject: Re: [Moo] Found a very annoying bug..

Thats true, it does look better.

About who's fault it is, I would expect a "foreach" loop not to try to itterate over an non existant element (at position 0 or whatever), the fact I am trying to use this nonexistent element later is not so evil IMO :)

for ( var thought in thoughts) { if (thought) alert("I think, therefor I exist!") }

On Tue, Dec 15, 2009 at 2:32 AM, Aaron Newton <[email protected]> wrote:
this is by far the better option.

it's not IE's fault that you are trying to reference something that doesn't exist. This isn't a bug in IE or MooTools.


On Mon, Dec 14, 2009 at 7:09 PM, Barry van Oudtshoorn <[email protected] > wrote:
What about doing something like

$each(arr, function(item) {
  if (item && item.foo) item.foo();
})

It's more robust and will mean that you can start indexing your arrays from whatever you want.


On 15/12/09 08:04, Roman Land wrote:

Indeed this code would cause an issue for me, since the issue is not due to referencing of the nonexistent item, rather inside the loop I do something like:

$each(arr, function(item, i) {
item.foo(); // this will throw an error on undefiled object and stop JS
})

My workaround by the way is to check weather i == 0 (this is a special array I use where I normally start at position 1).

FF's implementation does actually jump over position 0 - starting at 1, that would be logical interpretation of "foreach" vs "for (i =0 ; i < smt.length ; i++)" - where I tell him to begin at position 0 explicitly.

Cheers
-- Roman

On Tue, Dec 15, 2009 at 1:18 AM, Aaron Newton <[email protected]> wrote: Here is the code for forEach, implemented into browsers that do not implement it themselves:

forEach: function(fn, bind){
for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this [i], i, this);
}

as you can see, it loops over each item and calls your function, passing the array's value at i. This is undefined for your zero value. I don't know where IE would freak out on this (though it doesn't surprise me that it might). The code above references yourArray[index] that shouldn't throw an error...

Aaron

On Mon, Dec 14, 2009 at 12:31 PM, Roman Land <[email protected]> wrote:
Lolz on the kindly:)

Paul, this site is meant to work on all browsers, I currently have a
work around, this behavior is undesired despite it's roots being in ie
implementation of foreach.

Cheers, Roman

On 14/12/2009, at 18:28, Paul Saukas <[email protected]> wrote:


> Roman ,
>
>     I believe that is an IE issue . I have no problem running your
> example on IE8 . It just kindly spits undefined out in place of the
> missing element 0 if i have it display the items, If i do the keys
> then IE shows 01234 and ff 1234. What version of IE are you using ?




--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein



--
Not sent from my iPhone.




--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein




--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein




--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein




--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein

Reply via email to