473,594 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

are inner functions always properties?

Hi,
given two nested functions:

function outer() {
function inner() {
}
}

Is it determined by the ECMAScript standard that inner should be a
property of outer, thus a "document.write (outer.inner);" on the global
level outputs something like "function inner() { }"?
Olov Johansson

Jan 17 '06 #1
8 1509


ol************@ gmail.com wrote:

given two nested functions:

function outer() {
function inner() {
}
}

Is it determined by the ECMAScript standard that inner should be a
property of outer,


No, but Spidermonkey, the JavaScript engine in Netscape and Mozilla did
that for quite some time (for instance in Netscape 4.7, still in Mozilla
1.7).
But no longer in Firefox 1.5.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 17 '06 #2
On 17/01/2006 17:20, ol************@ gmail.com wrote:
function outer() {
function inner() {
}
}

Is it determined by the ECMAScript standard that inner should be a
property of outer [...]


No. Inner functions are local. It is almost exactly the same as:

function outer() {
var inner = function() {};
}

The only reason why an inner function should be a property of an outer
function is if it was assigned such during execution of the function body:

function outer() {
function inner() {}

outer.inner = inner;

/* Or:
* arguments.calle e.inner = inner;
*/
}

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 17 '06 #3
VK

ol************@ gmail.com wrote:
Hi,
given two nested functions:

function outer() {
function inner() {
}
}

Is it determined by the ECMAScript standard that inner should be a
property of outer, thus a "document.write (outer.inner);" on the global
level outputs something like "function inner() { }"?


Unless you have killed toString() method for Function like:
....
Function.constr uctor.prototype .toString = function(){retu rn
'function';}
....
Then you cannot have runtime access anymore to function bodies.

Jan 17 '06 #4
Thanks for your answers,
almost exactly you say, then what is the resulting difference
(according to the standard) for our two simple examples?

function outer() {
function inner() {
}
}

function outer() {
var inner = function() {
};
}
Olov Johansson

Jan 19 '06 #5
VK

Olov Johansson wrote:
Thanks for your answers,
almost exactly you say, then what is the resulting difference
(according to the standard) for our two simple examples?

function outer() {
function inner() {
}
}

function outer() {
var inner = function() {
};
}


If "according to the standard" then the first variant is simply illegal
as it is not allowed to nest function declarations. Whatever results
will be on a prticular browser - it depends on that particular browser.

The second variant creates local variable inner with the reference on
an anonymous function.

Jan 19 '06 #6
Nested functions (with lexical scope and closures) is indeed in the
standard. Have a look at
http://www.ecma-international.org/pu...t/ECMA-262.pdf
..
Olov Johansson

Jan 19 '06 #7
Olov Johansson wrote:
Thanks for your answers,
almost exactly you say, then what is the resulting
difference (according to the standard) for our two
simple examples?

function outer() {
function inner() {
}
}

function outer() {
var inner = function() {
};
}


The only difference is when the inner function object(s) is(are)
created. With a function declaration the function object is created and
assigned to a named property of the Activation/variable object during
'variable instantiation', prior to the execution of any code in the
function body. The second example creates a named property of the
Activation/variable object during variable instantiation but the
function object is not created until the right hand side of the
assignment expression is evaluated, during the execution of the function
body.

Richard.
Jan 19 '06 #8
On 19/01/2006 09:14, Olov Johansson wrote:
Nested functions (with lexical scope and closures) is indeed in the
standard.


Ignore VK.

As Richard said, the difference lies in when the function objects would
be created. The scope chain and other behavioural features remain the same.

function outer() {
inner();

function inner() {
}
}

would work as expected because the nested function, inner, would have
been created before execution of the function body had started.

function outer() {
inner();

var inner = function() {};
}

would fail. The local variable, inner, would exist (variable
declarations, like function declarations, occur before execution) but
the function object would not have been created, and a reference
assigned, until execution had reached that point in the function body.

[snip]

Mike
When replying through Google Groups, please do not use the 'Reply' link
at the end of the post. Instead, activate 'show options' at the top of
the post you want to reply to, and use 'Reply' from there. That post
will now be quoted.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2002
by: Irlan agous | last post by:
Hello i have t tables reactie and form and this query $sql = "select reactie.persid,form.oproep,form.foto,form.id from reactie,form INNER JOIN reactie ON (reactie.persid = form.id) group by reactie.persid order by reactie.persid DESC LIMIT 0,5"; $result = mysql_query($sql);
7
9752
by: Wolfgang Jeltsch | last post by:
Hello, I want to write a list class with an iterator class as an inner class. The iterator class must have access to certain private members of the list class in order to do its job. Here is a reduced code example: class List { private: void *rootNode; class Iterator {
1
1603
by: optimistx | last post by:
How to build or find an object browser for javascript? E.g. Delphi integrated developement environment ('ide') offers a very practical object browser for Pascal language. When typing a name with a dot you get a list of objects,properties and methods to select from. When you select or type a methodname or function and the left parenthesis , the system writes the possible argument types. With key F1 one gets thorough description of the...
3
2245
by: cybertof | last post by:
Hello, Is it possible in C# to have 2 overloaded functions with - same names - same parameters - different return type values If no, is it possible in another language ?
11
6788
by: Kondapanaidu | last post by:
Hi, What is the difference between Properties and functions. Why dont we go for functions instead of properties. Regrads
4
1119
by: trevor_morgan | last post by:
The following code: def functions(): l=list() for i in range(5): def inner(): return i l.append(inner) return l
3
2364
by: Dan Jacobson | last post by:
Let's say all one can do to override a document's link colors, <a href="FAQ.aspx"><font color="#0000ff">FAQ</font></a> is inject things like: <a href="FAQ.aspx"><span style="color:green"><font color="#0000ff">FAQ</font></span></a> only at the <A></Aedges (as I have done above setting WWWOFFLE's anchor-cached-begin value.) Which, depending on DOCTYPE, is not strong enough to override the most inner <fontwhen view in firefox. Nor does...
7
1875
by: chromis | last post by:
Hi there, I have three tables: -properties -propLocations -locations I am trying to allow each property to have more than one location. Locations holds the locations (id,name) and propLocations holds the references for each property so each row in this table has the ID of the property (propID) and the ID of the location propLocID.
3
4224
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: === def outer():
0
7941
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8368
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8231
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.