Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Nested function X vs. nested varX = function

Reply
Thread Tools

Nested function X vs. nested varX = function

 
 
Richard A. DeVenezia
Guest
Posts: n/a
 
      09-08-2003
These seem to do the same thing, beyond the source code differences, are
there any differences ?

function foo () {
y = bar(2)
return
function bar (x) {return x*x}
}

function foo () {
var bar = function(x) { return x*x }
y = bar(2)
return
}

I recall Lasse mentioning a one-pass. Now I see it, In the first foo the
bar function is available prior to it's definition because of the one-pass.
In the second foo, the function var bar has to be assigned before it can be
used.

Where is a good reference discussing the 'one-pass' or 'first-pass' ?

--
Richard A. DeVenezia


 
Reply With Quote
 
 
 
 
Code Ronin
Guest
Posts: n/a
 
      09-09-2003
"Richard A. DeVenezia" <(E-Mail Removed)> wrote in message news:<bji3j2$jjdus$(E-Mail Removed)-berlin.de>...

> Where is a good reference discussing the 'one-pass' or 'first-pass' ?


The ECMA-262 standards, although it will not use that terminology. See
the section on execution contexts.

> These seem to do the same thing, beyond the source code differences, are
> there any differences ?


I believe they are so minimal as to be irrelevant (unless someone sees
something I do not). But here is one. Change the "return" statements
to "return bar.toString()" and compare the results. The first is a
named function object; the second is an anonymous function object
assigned to a variable.

At first I was unsure of the intent of your first function's return.
Is it "return;" or "return function bar (x) {return x*x};"? I figured
it was the former, otherwise your question would not make sense.

If you use a code cruncher, the lack of ";" will bite you someday.
 
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
Nested friend class in nested template problem tonvandenheuvel@gmail.com C++ 3 12-07-2007 03:02 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Is nested class automatically friend of class that it is nested in? request@no_spam.com C++ 5 09-25-2006 08:31 AM
Nested Vector Nester Classes are Nested in my Brain Chad E. Dollins C++ 3 11-08-2005 04:46 AM
Nested iterators (well, not nested exactly...) Russ Perry Jr Java 2 08-20-2004 06:51 PM



Advertisments