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

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.prototype.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 1641
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.prototype.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
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...
1
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...
3
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...
5
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...
8
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...
5
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...
13
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(); } //...
3
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 -...
8
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.