Firefox 2.0 to 2.0.0.1 change in "for each (var element in array) {}"

Hello

I have a problem with an extension i am making. I often use the following bit 
of code:

for each (var element in myArray) {
     ...
}

However the code started to act strangely when i updated Firefox from version 
2.0 to version 2.0.0.1. Normally this loop runs one time for each element in 
the array, setting the variable "element" to one of the elements in the 
array. Hovever in Firefox 2.0.0.1 sometimes the following function is added 
to the end of the list:

function (value) {
     var i;
     for (i = 0; i < this.length; i++) {
         if (this[i] === value) {
             return true;
         }
     }
     return false;
}

I don't know where the function come from, and I haven't been able to produce 
a simple snip of code in which this behavior appeared. Changing my code to this:

for (var i = 0; i < myArray.length; i++) {
     var element = nyArray[i];
     ...
}

Solves my problem. But i am using the "for each" loop allot of times in my 
code. I would be happy if someone knew a trick that I could use, so that I 
won't have to edit all my loops.
0
Jesper
12/23/2006 6:16:29 PM
mozilla.dev.extensions 5694 articles. 0 followers. Post Follow

7 Replies
730 Views

Similar Articles

[PageSpeed] 33

Jesper Kristensen schreef:
> Hello
> 
> I have a problem with an extension i am making. I often use the
> following bit of code:
> 
> for each (var element in myArray) {
>     ...
> }
> 
> However the code started to act strangely when i updated Firefox from
> version 2.0 to version 2.0.0.1. Normally this loop runs one time for
> each element in the array, setting the variable "element" to one of the
> elements in the array. Hovever in Firefox 2.0.0.1 sometimes the
> following function is added to the end of the list:
> 
> function (value) {
>     var i;
>     for (i = 0; i < this.length; i++) {
>         if (this[i] === value) {
>             return true;
>         }
>     }
>     return false;
> }
> 
> I don't know where the function come from, and I haven't been able to
> produce a simple snip of code in which this behavior appeared. Changing
> my code to this:
> 
> for (var i = 0; i < myArray.length; i++) {
>     var element = nyArray[i];
>     ...
> }
> 
> Solves my problem. But i am using the "for each" loop allot of times in
> my code. I would be happy if someone knew a trick that I could use, so
> that I won't have to edit all my loops.

for ... in loops and for each ... in loops should be avoided for this
reason. Probably that function is defined by you. Try a for ... in loop
to get the name of the function, that might clarify something.

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:for...in#Description
0
Frederik
12/23/2006 7:26:38 PM
Frederik Vanderstraeten wrote:
> for ... in loops and for each ... in loops should be avoided for this
> reason. Probably that function is defined by you. Try a for ... in loop
> to get the name of the function, that might clarify something.
> 
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:for...in#Description

Thank you for your answer. I think I will just go through my code and change it.

On the for each ... in page on MDC there is an example of how to use it on 
arrays, but on the for ... in page there is a warning about using it on 
arrays. It seems I was misled by that first page.
0
Jesper
12/23/2006 7:39:17 PM
Jesper Kristensen wrote:
> Frederik Vanderstraeten wrote:
>> for ... in loops and for each ... in loops should be avoided for this
>> reason. Probably that function is defined by you. Try a for ... in loop
>> to get the name of the function, that might clarify something.
>>
>> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:for...in#Description 
>>
> 
> Thank you for your answer. I think I will just go through my code and 
> change it.
> 
> On the for each ... in page on MDC there is an example of how to use it 
> on arrays, but on the for ... in page there is a warning about using it 
> on arrays. It seems I was misled by that first page.

BTW, the name of the function was "inArray"
0
Jesper
12/23/2006 7:45:16 PM
On Sat, 23 Dec 2006 19:16:29 +0100, Jesper Kristensen wrote:

> I have a problem with an extension i am making. I often use the following bit 
> of code:

> for each (var element in myArray) {
>      ...
> }

Known problem. Some other extension added a method to the Array
prototype. Or perhaps the Object prototype.

> However the code started to act strangely when i updated Firefox from version 
> 2.0 to version 2.0.0.1. Normally this loop runs one time for each element in 
> the array, setting the variable "element" to one of the elements in the 
> array. Hovever in Firefox 2.0.0.1 sometimes the following function is added 
> to the end of the list:

> function (value) {
>      var i;
>      for (i = 0; i < this.length; i++) {
>          if (this[i] === value) {
>              return true;
>          }
>      }
>      return false;
> }

It looks like some idiot tried to reimplement the "some" method
<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some>
But it already exists in Firefox 1.5 and upwards.

-- 
-==-
Philip Chee <philip@aleytys.pc.my>, <philip.chee@gmail.com>
http://flashblock.mozdev.org/ http://xsidebar.mozdev.org
Guard us from the she-wolf and the wolf, and guard us from the thief,
oh Night, and so be good for us to pass.
[ ]4 food groups: fast, frozen, microwaved, and junk.
* TagZilla 0.059.4
0
Philip
12/24/2006 3:18:22 AM
On Sat, 23 Dec 2006 19:16:29 +0100, Jesper Kristensen wrote:

> for each (var element in myArray) {
>      ...
> }

> Solves my problem. But i am using the "for each" loop allot of times in my 
> code. I would be happy if someone knew a trick that I could use, so that I 
> won't have to edit all my loops.

You will still need to edit all your loops. The authors of DownThemAll
bit the bullet and changed all their loops. You could do something like:

for each (var element in myArray) {
    if (typeof element == "function") continue;
    ...
}

OR

for each (var element in myArray) {
    if (typeof element != <whatYouExpect>) continue;
    ...
}

Phil
-- 
Philip Chee <philip@aleytys.pc.my>, <philip.chee@gmail.com>
http://flashblock.mozdev.org/ http://xsidebar.mozdev.org
Guard us from the she-wolf and the wolf, and guard us from the thief,
oh Night, and so be good for us to pass.
[ ]I know so little, but I know it fluently...
* TagZilla 0.059.4
0
Philip
12/24/2006 3:23:33 AM
Philip Chee wrote:
> On Sat, 23 Dec 2006 19:16:29 +0100, Jesper Kristensen wrote:
> 
>> for each (var element in myArray) {
>>      ...
>> }
> 
>> Solves my problem. But i am using the "for each" loop allot of times in my 
>> code. I would be happy if someone knew a trick that I could use, so that I 
>> won't have to edit all my loops.
> 
> You will still need to edit all your loops. The authors of DownThemAll
> bit the bullet and changed all their loops. You could do something like:
> 
> for each (var element in myArray) {
>     if (typeof element == "function") continue;
>     ...
> }
> 
> OR
> 
> for each (var element in myArray) {
>     if (typeof element != <whatYouExpect>) continue;
>     ...
> }
> 
> Phil

OR

myArray.forEach(function(element){
   ...
});

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach

Array.forEach only deals with Array elements anyway, and if you're using 
| for each | you already are on a JS engine with it :)  The happy JS 
scoping also means you get access to all the variables in the parent 
scope (but thing you declare inside won't be shared out).

There's also stuff you can do (in JS 1.7) with custom iterators, but I 
find that too painful to deal with.

-- 
Mook
mook dot moz plus stuff at gmail dot commercial
0
Mook
12/24/2006 4:38:04 AM
I have already updated my code to use integer indexes. I remember that two 
extension updates was installed when i installed Firefox 2.0.0.1. I guess i 
wrongly blamed the Firefox update.
0
Jesper
12/24/2006 1:30:04 PM
Reply:

Similar Artilces:

Firefox "upgraded" itself from 2.0.0.12 to 2.0.0.7
Name: Pat Product: Firefox Summary: Firefox "upgraded" itself from 2.0.0.12 to 2.0.0.7 Comments: Update history is only displaying updates from 2.0.0.7 and below. Check for upgrades is not finding any. Updates were set to automatically download and install. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-AU; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7 ...

Have 2.0.0.3.
Name: Mickey Mouse Email: grabthebonusatgmaildotcom Product: Firefox Summary: Have 2.0.0.3. - just received 2.0.0.2. as an "Update"? Comments: Hi, I have version 2.0.0.3 installed. I just got a dialogue box telling me that I have received 2.0.0.2 as an update. This obviously doesn't make sense. What is going on here? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 ...

Installed 2.0.0.8, then it automatically "upgraded" itself to 2.0.0.6!!!
Name: Filip Giesz Email: filipgatrepairfaqdotorg Product: Firefox Summary: Installed 2.0.0.8, then it automatically "upgraded" itself to 2.0.0.6!!! Comments: I can send you details and gifs of the About dialog and the Update dialog. Bizarre. I'll be shutting the autoupdate in 2.0.0.8 OFF... ...

I like firefox 2.0.0.0 better than 2.0.0.1
Name: tsit chan Email: chantsitathkbndotnet Product: Firefox Summary: I like firefox 2.0.0.0 better than 2.0.0.1 Comments: 2.0.0.1 version allows minimized pages pop up when open multi- tabs in one page ,until this fixed i prefer 2.0.0.0 before any new release. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0 ...

firefox 2.0.0.1 and 2.0.0.2 download window problem
I am having a problem with the download options in the browser. Hope I can explain this correctly so it makes sense. I went to "options" "download" and tried changing it there for various settings with no change. Problem just started with 2.0.01 and unfortunately the browser updated to 2.0.0.2 before I could stop it but problems still there. My other computer works fine with both versions so I think something got corrupted but don't know what or how to fix it. I don't want to uninstall FF and reinstall it and lose all my bookmarks. Is there a r...

Buggy firefox 2.0.0.2 and 2.0.0.3
Name: badidea Email: very_bad_ideaathotmaildotcom Product: Firefox Summary: Buggy firefox 2.0.0.2 and 2.0.0.3 Comments: I don't know what changed since 2.0.0.1 but the new releases (2.0.0.2, 2.0.0.3) seem very buggy. Random crashes, slow responses and additionally problems with administrator rights. I had similar problems on 2 out of 2 systems. Best solution for me (and probably a lot of other users) is to go back to 2.0.0.1 and disable automatic update. Success! Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2....

Slogan: "Firefox 2.0
Name: Andrei Kharlanov Email: andrei.kharlanov_at_gmail.com Product: Firefox Summary: Slogan: "Firefox 2.0 - The best browser for the web 2.0" Comments: I have an idea and I hope it will be useful for Mozilla Foundation. So, I invented the advertising slogan: "Firefox 2.0 - the best browser for the web 2.0". Browser Details: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3 ...

Online Firefox Update ver. 2.0.0.0 to ver. 2.0.0.1 fails
Name: user - europe Product: Firefox Summary: Online Firefox Update ver. 2.0.0.0 to ver. 2.0.0.1 fails Comments: The online update ver. 2.0.0.0 to ver. 2.0.0.1 indicates that a number of files could not be updated resp. installed, although I folowed your instruction and closed as many running applications as possible. Browser Details: Mozilla/5.0 (Windows; U; Win98; en-GB; rv:1.8.1) Gecko/20061010 Firefox/2.0 ...

printing issues with firefox 2.0.0.1 and 2.0.0.3
Name: ledatica Email: ledaticaathotmaildotcom Product: Firefox Summary: printing issues with firefox 2.0.0.1 and 2.0.0.3 Comments: OS - windows XP home edition with SP2 After installing Firefox version 2.0.0.3 I noticed that web page printing is out of order, when the xp user account is a limited account. I checked to see the print preview and that showed me only partial page displayed and only prints partial page. I logged back on as XP admin account and checked the same web page again. This time both the print preview and the actual printing came out exactly as the web...

critical leak in security on firefox 2.0.0.1 and 2.0 #2
Name: Jimi Product: Firefox Summary: critical leak in security on firefox 2.0.0.1 and 2.0 Comments: Dear Sirs, I saw that you created new version of firefox 2 so I have just tested latest firefox 2.0.0.1. on the same problem that I had with firefox 2. So, after browsing again this time with 2 opened tabs I was testing switch proxy extension and than suddenly huge amount of data came on my computer seemingly out of nowhere. I stopped activities by pusshing stop loading this page icon on browser on both opened tabs although only on one the page was loading ...

Firefox version 2.0.0.3 is being updated to 2.0.0.2?
Name: Russell Nelson Email: rnelsonatgenedotcom Product: Firefox Summary: Firefox version 2.0.0.3 is being updated to 2.0.0.2? Comments: I am currently using a version of Firefox with the version number of 2.0.0.3. This is the second time that I have been told that it has now been updated to a newer version of Firefox with a version number of 2.0.0.2. I assume that 2.0.0.3 is newer (and better) than version 2.0.0.2. How can I stop this "update"? Russ Nelson 650-225-7212 Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.3) Gecko/20070...

updating 2.0.0.1 to 2.0.0.2 is confusing at best.
Name: Raymond Gray Email: rcg123atoptonlinedotnet Product: Firefox Summary: updating 2.0.0.1 to 2.0.0.2 is confusing at best. Comments: I tried a few times to find the upgrade at the Firefox web site but only found the complete 2.0.0.2 install file. then I used the HELP > Check for Updates and found, downloaded and installed the 2.0.0.2 update. When it was completed, I re-launched firefox and checked the ABOUT, which showed 2.0.0.2 Yet today I got a firefox notice that an update was available; checked ABOUT again and it's back to 2.0.0.1. This does not give me...

"Ghost" popup windows with Firefox 2.0.0.1 (Mac OS)
Hi all, Since the update from FF 1.5 to FF 2.0 on my Mac, I'm experiencing a strange problem. When I click on a link which is supposed to open a new window/popup, then it happens... absolutely nothing. The mouse sometimes switches into a "working" state for a few seconds, but that's all. The strange point is that is does exactly the same whatever the kind of "new window" event (javascript of HTML link with the suitable attribute). If I force the opening of this kind of HTML link in a new tab, then it works (but of course it is very ugly, since generally...

TB 2.0.0.24 last Tb 2.0. Sure thing, or just "not planned to upgrade"?
Just noticed what my TB says when I open it. It says that this is the last planned update for TB 2 -series. Mozilla team encourages people to "upgrade" to bug-ridden Tb 3. Is that the final word? I see at least one blocking bug in Tb 3 and that is that new account wizard that is so infuriatingly badly designed that it has no limits. IMO TB3 is still beta. Broken beta. At least import that new and improved upcoming new account wizard from TB 3.1 to Tb 3.0 before dropping support for Tb 2. Also I think there is still that msf-file corruption bug around, which is bad...

Web resources about - Firefox 2.0 to 2.0.0.1 change in "for each (var element in array) {}" - mozilla.dev.extensions

Resources last updated: 12/26/2015 2:59:26 PM