This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Hierdie gesprek is in die argief. Vra asseblief 'n nuwe vraag as jy hulp nodig het.

Firefox 22.0 serious closure bug

  • 4 antwoorde
  • 2 hierdie probleem
  • 1 view
  • Laaste antwoord deur cor-el

more options

We have run into what seems like a serious closure bug in Firefox 22.0.

The simple following code executes fine in IE and chrome etc. but fails in a very scary way in FireFox - it thinks the function is undefined !!!

if (true) {

   test();
   function test()  {
       alert("success")
   }

}

If the code is executed outside of the if statement (or if just the function definition is moved outside the if statement) everything is ok.

The same error occurs (not defined) inside other closures like do .. while etc.

We are scared. What did we miss?

We have run into what seems like a serious closure bug in Firefox 22.0. The simple following code executes fine in IE and chrome etc. but fails in a very scary way in FireFox - it thinks the function is undefined !!! if (true) { test(); function test() { alert("success") } } If the code is executed outside of the if statement (or if just the function definition is moved outside the if statement) everything is ok. The same error occurs (not defined) inside other closures like do .. while etc. We are scared. What did we miss?

Gewysig op deur mccodev

Gekose oplossing

This has been solved. Firefox is different from other browsers (as we know)... but here's why...

http://stackoverflow.com/questions/18079086/firefox-22-0-scope-bug

Lees dié antwoord in konteks 👍 0

All Replies (4)

more options

Just swap the order of the two statements and place the function definition before calling the function.

if (true) {
   function test()  {
       alert("success")
   }
 test();
} 
more options

Thank you for your time and advice... but that wasn't my point at all.

The point is this seems to be quite a big bug. Javascript by it's very nature can forward reference within scope. As I suggested, the code works fine in all other browsers.

I'm worried this is a huge new bug in Firefox - or worse a secret breaking change. Has anyone got a lead on this? This should work right ???? Is it just me??

Gewysig op deur mccodev

more options

Gekose oplossing

This has been solved. Firefox is different from other browsers (as we know)... but here's why...

http://stackoverflow.com/questions/18079086/firefox-22-0-scope-bug

more options

I've marked your previous post as the solution since you wrote that it has been solved (Firefox doesn't allow forward reference if a function is defined within a block).