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:[EMAIL PROTECTED]
Sent: Wednesday, July 09, 2008 6:34 PM
To: Allen Wirfs-Brock
Cc: [EMAIL PROTECTED]; [email protected]; 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
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss