FAQ Topic - What is a function statement? (2010-05-24)

J

John G Harris

Either that or that you can't read, Johnny: ES3 specs, page 162: "A.4
Statements"

So you copied this

A.4 Statements
Statement :

and then deleted the second word. Weird.

You can do it and it's not an error, see:
http://groups.google.com/group/comp.lang.javascript/msg/a8bf14d724e82d77
sooo, could you please post a example that proves your (and Garrett's)
point, *please* ?

You can write anything you like where it says Statement, but whatever it
is it's most certainly not an ECMAScript FunctionDeclaration.

If the browser or whatever accepts what you write it will then do
whatever its unpublished specification says, but it won't call it a
FunctionDeclaration because that would be a non-conformance in anything
claiming to conform to ECMAScript.

John
 
R

Ry Nohryb

So you copied this

  A.4 Statements
  Statement :

and then deleted the second word. Weird.

Not weird, it's called to copy-paste the text "A.4 Statements".
You can write anything you like where it says Statement, but whatever it
is it's most certainly not an ECMAScript FunctionDeclaration.

Q: It looks like a function declaration, walks like a function
declaration, and quacks like a function declaration, and the specs
*permit* a function declaration there because syntax extensions are
permitted, so what ?
A: That this FAQ entry is pointless in the way it's worded right now.
 
J

John G Harris

Q: It looks like a function declaration, walks like a function
declaration, and quacks like a function declaration, and the specs
*permit* a function declaration there because syntax extensions are
permitted, so what ?
A: That this FAQ entry is pointless in the way it's worded right now.

You need to be accurate : ECMAScript permits extensions, but it's only a
Function Declaration if you say it is.

As you do say it is, you have to require it to be processed the way that
ECMA 262 requires Function Declarations to be processed. That is, the
declaration is processed *before* the code surrounding it is executed.

As a result, the function is declared unconditionally. Even if the
declaration is inside an if, while, or for statement the declaration is
always actioned even if code execution never passes through the
declaration text.

As Function Declarations are actioned unconditionally it is completely
pointless to hide them inside any kind of Statement. It is worth while
pointing this out to beginners.

You have demonstrated that this is what IE and a few others do. You have
also demonstrated that Mozilla is incompatible. It is worth while
warning beginners of this : they can't predict how their code is going
to behave if they use this extension.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top