Functions as blocks

Brian Terlson Brian.Terlson at microsoft.com
Wed Mar 5 13:26:16 PST 2014


We have discussed, at length, the various ways in which browsers differ in their handling of functions-in-blocks:



```js

if(test) {

    function foo() { }

}

```



At the last TC-39 we approved semantics for block-scoped functions in sloppy mode. We did not discuss directly, that I recall, how the following should be handled:



```js

if(test) function foo() { }

```

Per spec I believe this is a syntax error, but all browsers seem to allow it (with minor differences in semantics similar to function-in-block scenarios).



Are implementers going to be making this an error or carrying forward this extension? If carrying forward, are there any objections to adding this extension to Annex B with minimal intersection semantics similar to F-I-B?



I haven't collected much data on this so I'm not sure what the prevalence is, but we'd err on the side of caution and continue supporting it unless other implementers are confident enough to remove it. If no one will be removing it, it makes sense to me to add this to Annex B. Eager to hear what others' thoughts are.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140305/4c93f180/attachment.html>


More information about the es-discuss mailing list