Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Funky function assignment question (Firefox vs. IE)

Reply
Thread Tools

Funky function assignment question (Firefox vs. IE)

 
 
Csaba2000
Guest
Posts: n/a
 
      03-06-2005
I thought assigning one function to another was fairly straightforward,
as the example below illustrates. So I was really surprised that IE 6
showed the alert while Firefox 1.0.1 failed.

It's easy to shore up Firefox by changing the elem=... line, below, to:
var elem = function (myId) {return document.getElementById(myId);}
Could any of the theory gurus shed some light on this discrepancy?


<body id=myBody onLoad="tryit()">
<script type='text/javascript'>
var elem = document.getElementById; // just say no to long function
names
function tryit() { alert (elem('myBody').id); }
</script></body>


Csaba Gabor from New York


 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      03-06-2005
Csaba2000 wrote:

> I thought assigning one function to another was fairly straightforward,


Assigning one "function" to another is, however this may not be true
with "methods". A method may depend on being called as a method of its
parent object:

var gEBI = document.getElementById;
gEBI(id); // fail
gEBI.call(document, id); // success

As I think the above demonstrates, the code used by Firefox depends
upon the this operator referring to the document object.

[snip]

> Could any of the theory gurus shed some light on this discrepancy?


This isn't a discrepancy - just a design decision/implementation
side-effect. There is nothing inherently correct nor incorrect in
either Microsoft's or Mozilla's approach.

[snip]

> var elem = document.getElementById; // just say no to long function
> names


Be sure to control wrapping when posting code. It's a good idea to
always wrap code to 70 characters or so.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      03-06-2005
Csaba2000 said:
>
>I thought assigning one function to another was fairly straightforward,
>as the example below illustrates. So I was really surprised that IE 6
>showed the alert while Firefox 1.0.1 failed.
>
>It's easy to shore up Firefox by changing the elem=... line, below, to:
>var elem = function (myId) {return document.getElementById(myId);}
>Could any of the theory gurus shed some light on this discrepancy?
>
>
><body id=myBody onLoad="tryit()">
><script type='text/javascript'>
>var elem = document.getElementById; // just say no to long function
>names
>function tryit() { alert (elem('myBody').id); }
></script></body>


In Firefox, getElementById searches for the id within
the document of which the function is an attribute.

You create window.elem, which is not an attribute of
any document.

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      03-07-2005
Csaba2000 wrote:
[...]
> <body id=myBody onLoad="tryit()">
> <script type='text/javascript'>
> var elem = document.getElementById; // just say no to long function
> names
> function tryit() { alert (elem('myBody').id); }
> </script></body>
>


I think a much better way of doing this (if it needs doing at
all) is:

var elem = function(id) {return document.getElementById(id)}

and call it with:

elem('anId');

However, if you wanted to make this more useful, then include
some of the dynWrite functionality from the group FAQ:

<URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html>

var elem = function(id) {
if (document.getElementById){
return document.getElementById(id)
} else if (document.all) {
return document.all[id];
}
}


--
Rob
 
Reply With Quote
 
Csaba2000
Guest
Posts: n/a
 
      03-07-2005
"Michael Winter" <(E-Mail Removed)> wrote in message
news:X4LWd.29925$(E-Mail Removed). uk...

> Be sure to control wrapping when posting code. It's a good idea to always
> wrap code to 70 characters or so.
>

Wow, thanks for those great replies Mike, Lee, and Rob. I learned something
new.

I hope you don't mind if I go off topic a bit. That wrap was an
oversight, but I may as well adjust my system right now. I'm
using (ahem) Outlook Express 6 until Thunderbird has its bugs
worked out (can't do wholesale ignores), and my current settings
(Tools/Options.../Send/Plain Text Settings...) are:
Message format: Uuencode / wrap text at 76 characters

This is not working for me (and hence not working for you).
So, should I set this to:
A) Message format: Uuencode / wrap text at 132 characters
B) Message format: MIME (quoted printable) / no word wrap setting
C) Neither is good, better to count characters

I'm only ever sending vanilla, plain text. And on my OE, options
A and B both show up just fine when I send longer lines. As a
matter of course, I am using the Enter key to format my own
text before sending, but I'd certainly appreciate being to have
wider width in my outgoing messages.

My real question is, does A or B negatively impact other
common newsreaders, or can I just choose one? I'd choose
B, I suppose (the benefit being that even if the post shows
wrapped in my reader, if I copy and paste to Notepad, it
retains the original lines), though it doesn't prefix quotations
(the post being responded to) with a '>' character.


Thanks,
Csaba


 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      03-07-2005
Csaba2000 wrote:
[...]
> I hope you don't mind if I go off topic a bit. That wrap was an
> oversight, but I may as well adjust my system right now. I'm
> using (ahem) Outlook Express 6 until Thunderbird has its bugs
> worked out (can't do wholesale ignores), and my current settings
> (Tools/Options.../Send/Plain Text Settings...) are:
> Message format: Uuencode / wrap text at 76 characters
>
> This is not working for me (and hence not working for you).
> So, should I set this to:

[...]

Dunno, I'm using Thunderbird 'cos it's cross-platform and, being
fairly new to usenet, the best I've come across. I tried all
sorts and whilst some swear by this agent or that, I found
Thunderbird best for me, despite its drawbacks.

--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Funky P-t-P T1, SBC says I have a timing problem, I say BS... Doug Cisco 4 07-25-2004 02:14 AM
Address Book is Funky Peter Arnold Firefox 1 07-13-2004 12:57 PM
Funky function Denis Remezov C++ 4 06-25-2004 11:14 AM
DNS funky when using Cisco IOS w/ IPFW Brian Bergin Cisco 0 02-02-2004 01:06 PM
Question about some funky behavior with array subscripts Pete C++ 7 11-14-2003 02:02 PM



Advertisments