Is the following a bug that needs to be fixed for ES 3.1?

liorean liorean at gmail.com
Thu Sep 4 14:27:12 PDT 2008


2008/9/4 Michael Daumling <mdaeumli at adobe.com>:
> The following code produces a "first is not a function" error:
>
>
>
> Array.prototype.first = function()
>
>       { return this.length == 0 ? null : this[0]; }
>
> // no semicolon here
>
> (function() { if ([1,2].first() == 1) alert ("OK"); }())

That's a quite well defined part of automatic semicolon insertion. I
don't think it's possible to do anything about it for general script.
In a stricter syntax mode or with an external opt-in, one could
possibly turn off automatic semicolon insertion except for when
semicolons are redundant (such as before closing curlies).

> IMHO, there should be a rule that if a function-expression is followed by
> anything with brackets (), it would require the function-expression to be
> bracketed as well, otherwise, the bracketed statement does not become part
> of the assignment.

Not only is that a radical complexification of the automatic semicolon
insertion mechanism, it's also an incompatible one.

> Can/should this be fixed for 3.1?

Doesn't sound like something for 3.1, and I wouldn't want to see it in Harmony.
-- 
David "liorean" Andersson


More information about the Es-discuss mailing list