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 illustrates the problem:
x=function(s) { print (s); } ('hi')
This dutifully prints 'hi'.
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.
Can/should this be fixed for 3.1?
Michael
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss