473,473 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Element and Node are second class citizens in IE land

In FF you can define the following ...

Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }

But it don't work in IE.

Basically in IE land Element and Node are second class objects with no
prototypical behaviour, unlike Object, Number, and friends.

Bad Microsoft !

Regards,

Aaron
Jul 13 '08 #1
12 1357
Aaron Gray wrote:
In FF you can define the following ...

Element.prototype.getClass = function() { return this.className; /*
or whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }

But it don't work in IE.

Basically in IE land Element and Node are second class objects with no
prototypical behaviour, unlike Object, Number, and friends.

Bad Microsoft !
No standard says that constructors and/or prototypes should be exposed
for W3C DOM defined interfaces (indeed it could easily be argued that
interfaces should not have constructors and/or prototypes).

Richard.

Jul 13 '08 #2
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote in message
news:g5*******************@news.demon.co.uk...
Aaron Gray wrote:
>In FF you can define the following ...

Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }

But it don't work in IE.

Basically in IE land Element and Node are second class objects with no
prototypical behaviour, unlike Object, Number, and friends.

Bad Microsoft !

No standard says that constructors and/or prototypes should be exposed for
W3C DOM defined interfaces (indeed it could easily be argued that
interfaces should not have constructors and/or prototypes).
My school of programming says you should not put up barriers where none are
needed, you just disempower programmers and power users.

Aaron
Jul 13 '08 #3
On Jul 12, 5:49 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
In FF you can define the following ...

Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }

But it don't work in IE.

Basically in IE land Element and Node are second class objects with no
prototypical behaviour, unlike Object, Number, and friends.

Bad Microsoft !
If you read the ECMAScript standard, you will see that Host Objects
can behave very differently than Native Objects.

Peter
Jul 13 '08 #4
On Jul 12, 6:44 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
"Richard Cornford" <Rich...@litotes.demon.co.ukwrote in message

news:g5*******************@news.demon.co.uk...
Aaron Gray wrote:
In FF you can define the following ...
Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }
Augmenting Built-in (i.e. Native or Host) prototypes is generally
considered a bad practice. It has burned many library authors (e.g.
Prototype.js authors) who have done it because it gives them a warm
fuzzy feeling to see some particular syntax. "Don't modify objects you
don't own" is commonly good advice.
[snip]
My school of programming says you should not put up barriers where none are
needed, you just disempower programmers and power users.
It is more important to deal with the reality of the current
situation. The browsers are what they are.
Peter
Jul 13 '08 #5
On Jul 12, 8:50*pm, Peter Michaux <petermich...@gmail.comwrote:
On Jul 12, 6:44 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
"Richard Cornford" <Rich...@litotes.demon.co.ukwrote in message
news:g5*******************@news.demon.co.uk...
Aaron Gray wrote:
>In FF you can define the following ...
>* *Element.prototype.getClass = function() { return this.className; /* or
>whatever */ }
>* *Element.prototype.setClass = function(c) { this.className = c; }

Augmenting Built-in (i.e. Native or Host) prototypes is generally
built-in object and Host object have distictly different meanings.

Augmenting a built-in object is considerably safer, in that the
outcome is likely to be defined by the EcmaScript 262 spec.

For example:

Error.prototype.toString = function() {
return this.name + ": " + this.message;
};

The "toString" property of Error.prototype is not defined as
ReadOnly.

It's not the most polite thing to do, in that it may interfere with
someone else's toString, so it's a good idea to at least make sure
you've got a broken feature before fixing it.
var result = Error.prototype.toString.call({name:"test"});
if(result == "[object Error]") {
// fix.
}

Augmenting Host object, OTOH, is not really defined by any standard
and results will vary from browsers and versions.

javascript:var e =
document.body.__proto__;void(e.__defineGetter__("c lientTop",
function() { return -1; }));alert(document.body.clientTop)

Safari3: alert "0"
Firefox3 alert "-1"

There is no official standard for "clientTop" or if it is present on
any element, if it should be an instance property, a getter in the
prototype, et c.
considered a bad practice. It has burned many library authors (e.g.
Prototype.js authors) who have done it because it gives them a warm
fuzzy feeling to see some particular syntax. "Don't modify objects you
don't own" is commonly good advice.
It is a very powerful technique.

It's not standardized.

"Don't modify objects you don't own" is good advice. Modifying
HTMLElement.prototype to add on extra features that can be used by
each element sort of puts the new functionality in the wrong place,
sometimes even causing a collision (like as in above, or could be with
a "document.getElementsByClassName" collision). It's not safe.

Garrett
>
Peter
Jul 13 '08 #6
Aaron Gray meinte:
In FF you can define the following ...

Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }

But it don't work in IE.

Basically in IE land Element and Node are second class objects with no
prototypical behaviour, unlike Object, Number, and friends.
That's because they're DOM elements, and not native JS objects.
Bad Microsoft !
I'd rather say, that augmenting DOM elements is bad practice.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jul 13 '08 #7
Gregor Kofler <us****@gregorkofler.atwrites:
I'd rather say, that augmenting DOM elements is bad practice.
Well, only because it's not guaranteed to work (and indeed doesn't
work in the most popular browser at this time).

Personally, I think it would be great if extending the Element
prototype would work everywhere. But then, I don't think there's
anything fundamentally wrong with extending Object.prototype and
friends either.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jul 13 '08 #8
On Jul 13, 1:20 am, dhtml <dhtmlkitc...@gmail.comwrote:
On Jul 12, 8:50 pm, Peter Michaux <petermich...@gmail.comwrote:
On Jul 12, 6:44 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
"Richard Cornford" <Rich...@litotes.demon.co.ukwrote in message
>news:g5*******************@news.demon.co.uk...
Aaron Gray wrote:
In FF you can define the following ...
Element.prototype.getClass = function() { return this.className; /* or
whatever */ }
Element.prototype.setClass = function(c) { this.className = c; }
Augmenting Built-in (i.e. Native or Host) prototypes is generally

built-in object and Host object have distictly different meanings.
Strike what I said. "Don't modify objects which you don't own" covers
the cases I'm describing whatever the correct technical terminology
happens to be.

Peter

Jul 13 '08 #9
On Sun, 13 Jul 2008 at 02:44:12, in comp.lang.javascript, Aaron Gray
wrote:
>"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote in message
news:g5*******************@news.demon.co.uk...
<snip>
>No standard says that constructors and/or prototypes should be exposed for
W3C DOM defined interfaces (indeed it could easily be argued that
interfaces should not have constructors and/or prototypes).

My school of programming says you should not put up barriers where none are
needed, you just disempower programmers and power users.
Another school says that rendering HTML should be fast and smooth. It's
less important if access by VBScript and javascript is slow and ugly.

John
--
John Harris
Jul 13 '08 #10
"John G Harris" <jo**@nospam.demon.co.ukwrote in message
news:V2**************@J.A830F0FF37FB96852AD08924D9 443D28E23ED5CD...
On Sun, 13 Jul 2008 at 02:44:12, in comp.lang.javascript, Aaron Gray
wrote:
>>"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote in message
news:g5*******************@news.demon.co.uk...

<snip>
>>No standard says that constructors and/or prototypes should be exposed
for
W3C DOM defined interfaces (indeed it could easily be argued that
interfaces should not have constructors and/or prototypes).

My school of programming says you should not put up barriers where none
are
needed, you just disempower programmers and power users.

Another school says that rendering HTML should be fast and smooth. It's
less important if access by VBScript and javascript is slow and ugly.
How come Gecko is faster then ?

Aaron
Jul 13 '08 #11
My school of programming says you should not put up barriers where none are
needed, you just disempower programmers and power users.

Aaron
Agreed,

This bug (and the corresponding bug in IE Feedback can be tracked
here:
http://webbugtrack.blogspot.com/2007...lelements.html

Max
Jul 15 '08 #12
On Jul 15, 4:10*am, webbugtr...@gmail.com wrote:
>My school of programming says you should not put up barriers where none
are needed, you just disempower programmers and power users.
>Aaron

Agreed,

This bug (and the corresponding bug in IE Feedback can be tracked
here:http://webbugtrack.blogspot.com/2007...lelements.html
A bug would be a discrepancy between actual behaviour and required
behaviour. As there is no requirement that DOM interface prototypes be
exposed their not being exposed cannot be a bug. Correcting a
discrepancy between actual behaviour and desired behaviour would be an
enhancement.

Incidentally, the "bug" report is not particularly accurate as it
asserts that there are no workarounds, while there are many.
(Including, but not restricted to, Prototypes.js' strategy of using a
single function to retrieve all elements and having that function
directly modify the elements it retrieves).

Jul 15 '08 #13

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

Similar topics

4
by: Jean-Christophe Michel | last post by:
Hi, In a complex merging of two (non ordered) xml files i need to keep track of the elements of the second tree that were already merged with first tree, to copy only unused elements at the end....
2
by: rosemm | last post by:
I am having another problem. I need to know when an element is not in a node. Here is an example ....... <NODE> <Element1/> <Element2/ value="SOMETHING"> </NODE> <NODE> <Element1/>
2
by: Michal Januszczyk | last post by:
I have a very simple XML document. <SmtpGatewayRules xmlns="http://www.foo.com/schema.xsd"> <rules> <rule> </rule> </rules> </SmtpGatewayRules> When no xmlns is specified I can find rule...
0
by: jstathan | last post by:
Starting off, here's the page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"...
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
4
by: Jethro | last post by:
I've tried to find the simplest demonstration of my issue. I have source XML that looks like this (not a real XSD schema, but it doesn't matter at this point): (in var xmlStr:) <xsd:element...
9
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified,...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
53
by: Aaron Gray | last post by:
Due to M$'s stupidity in not making DOMElements first class citizens the following will not work :- function isElement( o) { return o instanceof Element } It works for FF, Opera and Safari.
0
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,...
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...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.