Newly revised Section 10 for ES3.1.
Allen Wirfs-Brock
Allen.Wirfs-Brock at microsoft.com
Wed Jul 9 21:42:37 PDT 2008
Yes, but
<script>
function g() {
if (true) {
function f() { alert("1"); }
}
Else {
function f() { alert("2"); }
}
f();
}
g();
</script>
doesn't yield consistent results across browsers. Even if we can craft a specification that just captured those aspects of block nest function declarations that are identical in the 4 principal browsers would It's not clear that anybody would be very happy with the result. (For example, a function of a given name can occurs in at most one conditionally executed block). Arguably, one "advantage" of my proposal is that it equally breaks all the existing implementations of block nested function declarations.
From: Maciej Stachowiak [mailto:mjs at apple.com]
Sent: Wednesday, July 09, 2008 6:34 PM
To: Allen Wirfs-Brock
Cc: es3.x-discuss at mozilla.org; es4-discuss at mozilla.org; Mark S. Miller; Herman Venter; Pratap Lakshman (VJ#SDK); Douglas Crockford
Subject: Re: Newly revised Section 10 for ES3.1.
On Jul 9, 2008, at 5:16 PM, Allen Wirfs-Brock wrote:
Const and function declarations within blocks must be uniquely named, such a declaration may not over-write a preceding declaration in the same block and an attempt to do so is a syntax error. Such declarations, of course, shadow any like named declarations in enclosing scopes. Since consts and function declarations in blocks are new, this is a new semantics.
Although the standard does not allow block-level function declarations, the following will parse and give identical results in all four of the major browsers (it will alert "2"):
<script>
function g() {
if (true) {
function f() { alert("1"); }
function f() { alert("2"); }
}
f();
}
g();
</script>
This example will interoperably alert "1":
<script>
function g() {
if (true) {
function f() { alert("1"); }
}
f();
}
g();
</script>
As I understand it, your proposal would make the first example a syntax error and the second a runtime error (unless a global function named f is defined).
I know from experience that sites do accidentally depend on the intersection of the different IE and Firefox extensions for block-level function declarations (and the Safari and Opera attempts to emulate them). Do you have evidence that leads you to conclude that your proposed behavior is compatible with the Web? I am almost certain it is not.
Regards,
Maciej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080709/5d1aa208/attachment-0002.html
More information about the Es4-discuss
mailing list