473,466 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

function redefinition and the standard

Hello,

In IE, when you redefine a function it will be overwriten by the latest
declaration.

Is that by the standard or by this browser implementation?

--
Elias
Jul 20 '05 #1
2 5476
lallous wrote:
Hello,

In IE, when you redefine a function it will be overwriten by the latest
declaration.

Is that by the standard or by this browser implementation?

--
Elias


function abc() { alert('hi'); }
function abc() { alert('bye'); }
abc();

is equivilent to

var abc = new Function("alert('hi');");
var abc = new Function("alert('bye');");
abc();

so unless a browser is doing something interesting parsing the included
JavaScript, it will always execute the last function defined with a
particular name.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
Grant Wagner <gw*****@agricoreunited.com> writes:
function abc() { alert('hi'); }
function abc() { alert('bye'); }
abc();

is equivilent to

var abc = new Function("alert('hi');");
var abc = new Function("alert('bye');");
abc();


While the conclusion is correct, this statement is slightly incorrect.
(I.e., ignore this unless you are a pedant like me :)

When Javascript interprets a block of code, it first treats all the
function declarations in the order they appear, i.e., it creates the
local variable and assigns their value. Then it treats all the
variable declarations and declares the variables (i.e., creates them
as properties of the variables object if they don't exist already),
but does not assign a new value, even if the declaration looks like
"var foo=42;". That is treated like "var foo;foo = 42;".
Then it executes the code, including the assignments to variables.

So

var foo = 42;
function foo(){}
alert(foo);

will alert "42".

In any case, declaring a function or variable will create it as a
local variable, a property of the variable object of the
scope. Creating it twice is allowed, and the last assignment to it
will win (functions first, in the order they appear, then assignments
in the normal code, in the order the are executed).
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

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

Similar topics

5
by: lomat | last post by:
Hello, While compiling a file, I get following error .... ================================= /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++/type_traits.h:14 2: redefinition of...
1
by: squallions | last post by:
Hi I doing my c++ homework and stuck on error 'class' type redefinition. I have 5 classes. First class is base class. The next two classes are derived from the first class. The next two...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
13
by: Roy Hills | last post by:
I've seen two different function prototype formats used for ANSI C, and I'm unsure as to which is the correct or preferred one. 1st Format (this is what I use) type function(type, type, type);...
3
by: hugheslin | last post by:
Hi, Please consider the following classes: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class Shape {...
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
5
by: Patrick Kowalzick | last post by:
Hi all, Is this valid? I do not find the case in the standard: void foo( int ) {} #define FOO foo int main() {
7
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to what is the exact difference between a virtual function and a pure virtual function? Thanks in advance!!!
9
by: pauldepstein | last post by:
On my visual c++ compiler, I compiled code which contained something like for( int i =0; i < 5; i++) { double x =5;} I expected it to give a compiler error because x is being redefined
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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 ...

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.