"dr.bob" <dr.bobik+> wrote in message
news:d76vvp$9er$...
>> var gE = document.getElementById;
>> var foo = gE("foo");
>>
>> does not?
>
> well, read this the other way around
it's no surprise to me
> that the former works, but i expected the latter to work as well.
> what am i getting wrong?
Actually, the latter does work in Internet Explorer.
An explanation of why is available at <url:
http://blogs.msdn.com/ericlippert/ar...20/231852.aspx />
So here's what happens when you say foo = document.write; First,
JScript attempts to resolve "document". It can't find a local or global
variable called that, so it asks the global window object for the
document property. IE gives back the document object. JScript then
asks the document object to give back the value of the write property.
IE creates an object which has a default method. The default method
calls the write function, but no one calls the method yet -- we just
have an object which, when invoked, will call the mehtod. JScript
assigns the object to foo. Then when you call foo("hello"); JScript
invokes the default method on the object, which calls the write method.
--
Grant Wagner <>
comp.lang.javascript FAQ -
http://jibbering.com/faq