Real World Func Decl in Block Scope Breakages

Brian Terlson Brian.Terlson at microsoft.com
Wed Dec 26 14:43:52 PST 2012


Most of the snippets fall into either column 5 or 10 in the output table on this site[1] (which is down, hence cached copy, hopefully it works for you guys). These are mostly interoperable across browser.

1. http://cc.bingj.com/cache.aspx?q=new-es5-strict-mode-requirement-function-statements-not-at-top-level-of-a-program-or-function-are-prohibited&d=4643002220544120&mkt=en-US&setlang=en-US&w=U93XPP_KaQ0_ZPk7dkr1Ij8kiT-SHMWI



From: es-discuss-bounces at mozilla.org [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Brandon Benvie
Sent: Wednesday, December 26, 2012 2:38 PM
To: Allen Wirfs-Brock
Cc: es-discuss at mozilla.org
Subject: Re: Real World Func Decl in Block Scope Breakages

This appears to be correct. A number of the examples can be boiled down to the following test:

    if (false) {
        function x(){
          console.log('worked');
        }
    }
    x();


In Chrome, IE, Opera, and Safari 'worked' will be logged. In Firefox it will silently fail.

On Wed, Dec 26, 2012 at 5:22 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote: 
Essentially only,  uses of this form are currently interoperable among all major implementations:

if (condition) {
     function foo() {};
     foo();   //function declared and invoked in same conditional blocks.
}

Other uses (without other explicit feature or browser detection logic being involved) are not likely to be interoperable.

I haven't looked in detail at all of Brian's snippets.  But several that I have glanced at look to me like they wouldn't be interoperable among current browsers.



More information about the es-discuss mailing list