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