[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

[FAQ]Function with "two" names

ram

6/11/2015 4:51:00 AM

Sorry, this surely is an FAQ, but what is this
(in the outermost scope, that is, in global scope)?

a01 = function a02() {};

I have entered in Firefox:

console.dir( this );

and it now shows:

Window -> about:blank
> IntallTrigger: InstallTriggerImpl
> a01: a02()
> alert: alert()
> ...

When I enter

a01

into the console, I get

function a02()

, but when I enter

a02

, I get

ReferenceError: a02 is not defined

. So it seems »a02« is more like a comment with not real meaning?

I can also enter

a03 = function() {}
function a04() {}

And then console.dir( this ); gives:

Window -> about:blank
> IntallTrigger: InstallTriggerImpl
> a01: a02()
> a03: a03()
> a04: a04()
> alert: alert()
> ...


1 Answer

John Harris

6/11/2015 8:43:00 AM

0

On 11 Jun 2015 04:50:36 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
wrote:

> Sorry, this surely is an FAQ, but what is this
> (in the outermost scope, that is, in global scope)?
>
>a01 = function a02() {};
>
> I have entered in Firefox:
>
>console.dir( this );
>
> and it now shows:
>
>Window -> about:blank
> > IntallTrigger: InstallTriggerImpl
> > a01: a02()
> > alert: alert()
> > ...
>
> When I enter
>
>a01
>
> into the console, I get
>
>function a02()
>
> , but when I enter
>
>a02
>
> , I get
>
>ReferenceError: a02 is not defined
>
> . So it seems »a02« is more like a comment with not real meaning?
>
> I can also enter
>
>a03 = function() {}
>function a04() {}
>
> And then console.dir( this ); gives:
>
>Window -> about:blank
> > IntallTrigger: InstallTriggerImpl
> > a01: a02()
> > a03: a03()
> > a04: a04()
> > alert: alert()
> > ...
>

See the Note in ECMA 62 v3 & v5.1, section 13 :

"NOTE The Identifier in a FunctionExpression can be referenced from
inside the FunctionExpression's FunctionBody to allow the function to
call itself recursively. However, unlike in a FunctionDeclaration, the
Identifier in a FunctionExpression cannot be referenced from and does
not affect the scope enclosing the FunctionExpression."

John