Is the following a bug that needs to be fixed for ES 3.1? [minor correction]

# David-Sarah Hopwood (17 years ago)

David-Sarah Hopwood wrote:

Michael Daumling wrote:

Hi all,

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"); }())

If the two statements are separated via a semicolon, there is no error.

The problem is that the second statement is treated as a function argument to the function-expression.

This is not a bug.

A semicolon clearly can't be inserted here because it would change the meaning of a valid program

I meant to say "of a syntactically valid program".

-- as opposed to making an invalid program valid as in other cases of semicolon insertion. (Nor should we even be considering any extensions to semicolon insertion, which is and always was simply a bad idea.)

The program also can't be made invalid

syntactically invalid