473,395 Members | 1,458 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,395 software developers and data experts.

Funky function assignment question (Firefox vs. IE)

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
Jul 23 '05 #1
5 1378
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.
Jul 23 '05 #2
Lee
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.

Jul 23 '05 #3
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
Jul 23 '05 #4
"Michael Winter" <m.******@blueyonder.co.invalid> wrote in message
news:X4******************@text.news.blueyonder.co. 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
Jul 23 '05 #5
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
Jul 23 '05 #6

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

Similar topics

3
by: Zac Panepucci | last post by:
Hello There, I am using the following constructs to parse named arguments: function whatever() { if (this.yo) { if(this.yo=='man') alert('wuzup'); else
1
by: Björn Langhof | last post by:
Hello. I'd like to overwrite a native function. It's the reload()-function of the document.location-object. My idea: document.location.reload = function(){alert('foo')}; So if the function...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
3
by: VirGin | last post by:
I am passing an object by reference to a function that is supposed to populate it with current data. Both the destination object and the source have nested std::lists, some branches of the lists...
8
by: BClareS | last post by:
Sorry, I have found my mistake, but I cannot delete this post. I have discovered by experiment that element.style.top assignment in IE works with just a number on the right but in Firefox you have...
3
by: Robert | last post by:
Hi, I thought I pretty much understood the whole prototype chain stuff, but now I stumbled upon a difference between IE and Firefox, that is totally confusing me. An example.......
3
by: RobG | last post by:
There has been a discussion on the iPhone web development group where an opinion has been expressed that function expressions are bad for performance and can be avoided by using function...
12
Plater
by: Plater | last post by:
Well, I'm stuck asking you all, because I cannot find a piece of code that works in multiple browsers. I have the following code that works in google chrome and ie: //Add a keypress watcher to...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.