473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Why these codes not worked well in IE7.

I wrote these codes:
function aaa()
{
}
aaa.nnnn = "now is aaa";
alert(aaa.nnnn);

eval("func = " + aaa.toString());

alert(aaa.nnnn);
func.nnnn = "now is func";
alert(aaa.nnnn);
alert(func.nnnn);

is worked well in FF2b and Opera9, but it not worked in IE7.
in FF2b and Opera9 it outputs:
now is aaa
now is aaa
now is aaa
now is func
but in IE7 it outputs:
now is aaa
undefined
undefined
now is func

will someone tell me why? IE7's bug??

Sep 20 '06 #1
4 2130
Hatter wrote:
I wrote these codes:
function aaa()
{
}
aaa.nnnn = "now is aaa";
alert(aaa.nnnn);

eval("func = " + aaa.toString());

alert(aaa.nnnn);
func.nnnn = "now is func";
alert(aaa.nnnn);
alert(func.nnnn);

is worked well in FF2b and Opera9, but it not worked in IE7.
in FF2b and Opera9 it outputs:
now is aaa
now is aaa
now is aaa
now is func
but in IE7 it outputs:
now is aaa
undefined
undefined
now is func

will someone tell me why?
I can't tell you why, but I can explain what appears to be happening.
Your eval statement is effectively:

var func = function aaa(){};
Which assigns a function object to func and gives it a name 'aaa'. In
IE, an 'aaa' property is added to the global object which references
what appears to be a copy or another instance of the same function
object, replacing the previous 'aaa' property and giving the appearance
of removing the public properties of aaa.

A simpler test that does the same thing is:

var func = function fred (){};
alert( typeof window.fred); // Shows function in IE, undefined in Fx
alert( func.toString() == fred.toString() ); // shows true in IE
Note that in IE, func and fred are different (though virtually
identical) objects, they are not references to the same object:

alert( func == window.fred) // shows false
func = '';
alert(typeof func) // shows 'string'
alert( typeof window.fred); // shows 'function'

IE7's bug??
Dunno, is it a bug? Anyhow, the above is from IE 6 so it is not
peculiar to IE 7 :-)
--
Rob

Sep 20 '06 #2
thanks Rob's answer.

I found a solution that declare aaa function like this:
aaa = function (){};

it worked well like FF2b or Opera9

Sep 20 '06 #3

jh*****@gmail.com wrote:
thanks Rob's answer.

I found a solution that declare aaa function like this:
aaa = function (){};
I guess we could quibble here and say that isn't a function
declaration, it is initialising aaa with a function expression that
creates an anonymous function object.

function declaration: function aaa(){}
function expression: var aaa = function(){}

The difference is that in a function expression, the name is optional.
It is interesting to note that in IE, function expressions with names
are added as properties of the global object.
--
Rob

Sep 20 '06 #4

RobG wrote:
[...]
The difference is that in a function expression, the name is optional.
It is interesting to note that in IE, function expressions with names
are added as properties of the global object.
Here's an iteresting scenario:

<script type="text/javascript">
var b;
var a = function b (){};
alert(
'a: ' + (typeof a)
+ '\nb: ' + (typeof b)
+ '\na=b? ' + (a==b)
)
</script>

In IE (I tested 5.2 on Mac OS), a==b gives true, in other browsers b is
undefined and hence show false.
--
Rob

Sep 20 '06 #5

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

Similar topics

8
by: Shane Groff | last post by:
I know this is a recurring discussion (I've spent the last 3 days reading through threads on the topic), but I feel compelled to start it up again. After reading through the existing threads, I...
1
by: Don | last post by:
Hi, I try to get a simple applet working, the class-file does load, but the image doesn't appear;( An error doesn't appear. The view is and stays 'grey' What I want: Automatic refresh of a...
4
by: Paul T. RONG | last post by:
Dear All, I add two new tables to the database and then the disable shift key codes don't work. These two new tables are actually created by two queries, and only these two are in the front end,...
16
by: Fao, Sean | last post by:
As far as I can tell, the standard has defined three portable return codes from function main() (0, EXIT_SUCCESS, EXIT_FAILURE). Personally, on all platforms I have worked with, EXIT_SUCCESS is,...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
2
by: ForsakenAnR | last post by:
Hello is there is any one out there that can help me i just been given this exercise to do and i have done most of it i just need help on alittle bit... The bit i need help on is adding the over...
3
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
0
by: deena22 | last post by:
Hello i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype, date,...
1
by: Temidayo | last post by:
Please, Resourceful Members of the House, I tried to perform a search in ASP.NET (which I implemented in VB.NET and worked successfully) with the following lines of codes: Protected Sub...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.