Newly revised Section 10 for ES3.1.
Maciej Stachowiak
mjs at apple.com
Wed Jul 9 18:33:31 PDT 2008
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/921d12b8/attachment-0002.html
More information about the Es4-discuss
mailing list