Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Newbie: how to understand the argument in overwritten function

Reply
Thread Tools

Newbie: how to understand the argument in overwritten function

 
 
sasuke
Guest
Posts: n/a
 
      12-28-2007
On Dec 26, 11:21 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> What the both of you apparently overlook is that
>
> var f = function ...
>
> and
>
> function f...
>
> differ significantly in the regard of evaluation order.
>
> There is only one important rule to apply here: variable instantiation comes
> *before* execution. *But* the term "variable instantiation" is not to be
> confused with "variable initialization".
>
> That means in all instances `f' is instantiated before execution, however
> only in the second instance it is declared as a reference to a Function
> object upon variable instantiation. Accordingly, in the first instance it
> is declared having the `undefined' value upon variable instantiation and
> only when execution reached that line, is assigned the Function object
> reference.
>
> See also ECMAScript Edition 3 Final, 10.1.3 (again).


1. In both the cases, the instantiation of the variable results it in
having a value of 'undefined'. But in the case of function
declarations, which are evaluated before any code is executed, the
reference to the newly created function object (the one created by
function declaration) is assigned to the variable "TheFunction".

2. Whereas in the case of function definition the variable
"TheFunction" when instantiated will as usual have a value of
undefined but won't be assigned any function object reference unless
the code is actually executed. Because of this each onclick has a
different event listener.

3. var a; //variable declaration
var a = 10; //variable declaration and initialization (definition)

4.
<script type="text/javascript">
var a = someFunc(); //assigned before the code is executed
var a = (function() { /* someFunc(); */ })(); // assigned at the time
of execution
</script>

Am I correct in this reasoning and concept?
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-28-2007
sasuke wrote:
> On Dec 26, 11:21 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
> wrote:
>> What the both of you apparently overlook is that
>>
>> var f = function ...
>>
>> and
>>
>> function f...
>>
>> differ significantly in the regard of evaluation order.
>>
>> There is only one important rule to apply here: variable instantiation comes
>> *before* execution. *But* the term "variable instantiation" is not to be
>> confused with "variable initialization".
>>
>> That means in all instances `f' is instantiated before execution, however
>> only in the second instance it is declared as a reference to a Function
>> object upon variable instantiation. Accordingly, in the first instance it
>> is declared having the `undefined' value upon variable instantiation and
>> only when execution reached that line, is assigned the Function object
>> reference.
>>
>> See also ECMAScript Edition 3 Final, 10.1.3 (again).

>
> 1. In both the cases, the instantiation of the variable results it in
> having a value of 'undefined'.


Wrong. Have you even read what I posted? Have you cross-checked with the
Specification? In case of a FunctionDeclaration, the current Variable
Object is added a property that is initialized with a reference to a
Function object, which is clearly different from `undefined'.

> But in the case of function declarations, which are evaluated before any
> code is executed, the reference to the newly created function object (the
> one created by function declaration) is assigned to the variable "TheFunction".


*All* declarations are evaluated before any code is executed,
FunctionDeclarations make no exceptions. However, that is only the
declaration. This means that in any case the Variable Object is augmented
with a property; in the case of a variable it does _not_ mean the
initialization of the variable which would include the evaluation of the
optional AssignmentExpression and so the evaluation of the right-hand
operand of that expression.

> 2. Whereas in the case of function definition the variable
> "TheFunction" when instantiated will as usual have a value of
> undefined but won't be assigned any function object reference unless
> the code is actually executed. Because of this each onclick has a
> different event listener.


Obviously you have not read anything I have posted.

> 3. var a; //variable declaration
> var a = 10; //variable declaration and initialization (definition)


True.

> 4.
> <script type="text/javascript">
> var a = someFunc(); //assigned before the code is executed
> var a = (function() { /* someFunc(); */ })(); // assigned at the time
> of execution


Nonsense.

> Am I correct in this reasoning and concept?


Not at all. And if you had simply read what I posted and cross-checked with
the Specification, or have used a debugger, you would not have had to put
time in wording your wild assumptions.


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM



Advertisments