473,797 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending the DOM interfaces

In order to keep subsequent code clear, I added a new method like this

HTMLDivElement. prototype.foo = function(arg) {
// foo for HTML div trees
}

Element.prototy pe.foo = function(arg) {
// foo for XML tree retrieved using XMLHttpRequest
}

Since I had used the same approach for extending Array in IE 5.0, I
thought this was a cross-browser compatible approach. I was so naïve!
It seems this works in gecko-based browsers only.

Is there a trick for making this work in IE 6, Safari and Opera 8? Or
should I write two functions like this
function fooHtml(elt, arg) {
// ...
}
function fooXml(elt, arg) {
// ...
}
?

--
Henri Sivonen
hs******@iki.fi
http://hsivonen.iki.fi/
Jul 23 '05 #1
2 1675
I commiserate with you...

There was a related discussion (Attaching a method to DOM elements - March 7) at
http://groups-beta.google.com/group/...d3cfb75c080f7/

which was kicked off by Funky function assignment question (Firefox vs. IE)
http://groups-beta.google.com/group/...e2bbfa81aa1f7/

I am very skeptical about the speed of the offered IE method, besides objecting
to having to provide an extra file. I guess one should do experiments to see
whether the attachment in the IE method attaches the function to each
instance or not. If so, may as well just iterate through with javascript.

Csaba Gabor from Vienna
Henri Sivonen wrote:
In order to keep subsequent code clear, I added a new method like this

HTMLDivElement. prototype.foo = function(arg) {
// foo for HTML div trees
}

Element.prototy pe.foo = function(arg) {
// foo for XML tree retrieved using XMLHttpRequest
}

Since I had used the same approach for extending Array in IE 5.0, I
thought this was a cross-browser compatible approach. I was so naïve!
It seems this works in gecko-based browsers only.

Is there a trick for making this work in IE 6, Safari and Opera 8? Or
should I write two functions like this
function fooHtml(elt, arg) {
// ...
}
function fooXml(elt, arg) {
// ...
}
?

Jul 23 '05 #2


Henri Sivonen wrote:
In order to keep subsequent code clear, I added a new method like this

HTMLDivElement. prototype.foo = function(arg) {
// foo for HTML div trees
}
Since I had used the same approach for extending Array in IE 5.0, I
thought this was a cross-browser compatible approach. I was so naïve!
It seems this works in gecko-based browsers only.
Array is a native object in ECMAScript and for those the constructor
functions and the prototypes are exposed and properties and methods can
be added. But <div> element objects are host objects, and the ECMAScript
specification doesn't in any way require that constructor functions of
host objects are exposed. Nor does the W3C DOM ECMAScript binding, there
are only a few interfaces where you could read that binding as requiring
the constructor function to be exposed to have static properties like
node type constants.
Is there a trick for making this work in IE 6, Safari and Opera 8? Or
should I write two functions like this
function fooHtml(elt, arg) {
// ...
}
function fooXml(elt, arg) {
// ...
}
?


If you want to cover all those browsers you probably need to use that
approach with functions.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

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

Similar topics

4
9112
by: Carl Youngblood | last post by:
I imagine this subject has probably been brought up numerous times. Forgive me for bringing it up again. I was googling through old posts on this newsgroup about it and found a good suggestion on how to add functionality to the string class. Rather than trying to inherit from the string class, the author was suggesting wrapping the string class in another class, like so: >Right !!!, we should not derive from string, but we should wrap...
1
1850
by: Matthias Kaeppler | last post by:
Sorry if this has been discussed before (I'm almost certain it has), but I didn't know what to google for. My problem is, I have a class, a gtkmm widget, and I want it to serve as a base class now, but I'm not sure if I'm taking the proper steps in order to not break the whole class. Are there any guidelines what I have to watch out for? One question would e.g. be:
3
2228
by: Flip | last post by:
I'm looking at the O'Reilly Programming C# book and I have a question about extending and combining interfaces syntax. It just looks a bit odd to me, the two syntaxes look identical, but how does C# know which is extending and which is combining? interface IStorable{ void Read(); void Write(object o); }
5
2943
by: needin4mation | last post by:
Hi, I read this in a book about the Xml classes in c#: "These classes are abstract and therefore must be extended." I just wanted to know what this statement means. I know it is not in context, but the author gave it in such a matter that it appears experience folks will know what it means to say a class is abstract and extended. Thanks.
8
5444
by: Mark Olbert | last post by:
I'm writing a custom MembershipProvider which uses a custom class derived from MembershipUser (basically, the derived class adds a field to the MembershipUser base class). When I try to configure my website using the ASP.NET Configuration tool, and go to the Security page, I get the following error: Could not load type 'OMLMembershipUser' from assembly 'App_Code.olsckwwk, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Yet...
5
3834
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
13
2125
by: interec | last post by:
I have some code in Java that I need to translate into C++. My Java code defines a class hierarchy as follows: // interface IA public interface IA { public abstract void doA(); } // interface IB
3
3678
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
8
2377
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link, edit link, show linklist), comments (add comment, show commentlist) etc. I do not need all this functionality on every page. Ideally I could just extend the controller like this
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10205
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.