3 ms·
It isn't, it just has different incorrect behavior. As stated in the article, function declarations shouldn't be supported as statements at all -- but FireFox D
by tolmasky 15y ago
It isn't, it just has different incorrect behavior. As stated in the article, function declarations shouldn't be supported as statements at all -- but FireFox DOES support them, it just doesn't go as far as to hoist them. This seems like a bad compromise: because it half supports the feature but surprises you in that it works subtly differently. It probably wasn't a conscious decision but rather the result of fixing some random compatibility issue with a site that expected to be able to use functions declarations as statements but didn't rely on hoisting.
- azakai 15y agoThe article states that Firefox's behavior is according to the spec. I didn't read the spec myself, did you do so and see that the article is wrong?
- spjwebster 15y agoPlease read again. I said: "Firefox doesn’t actually issue a warning, which would have made my job tracking this issue down much easier. Moreover, functions declared within a block before being called work just fine, so it's not that function declarations can't by used as statements so much as SpiderMonkey won't bother to hoist them before executing any other code in that block." As I said, the grammar in the ECMA-262 spec only allows Statements within Blocks, and a FunctionDeclaration isn't a Statement. None of the browsers adhere to the spec, but I suspect they're just trying to play nicely with legacy content. Firefox just happens to play differently to all the other browsers.
- azakai 15y agoI see, thanks for the clarification!