Node.prototype.removeChildren CANNOT WORK IN IE BUT FF?

Z

zhong.zx

I need to expand the DOM object function for conviniency as following:

Node.prototype.removeChildren = function() {
while( this.lastChild) this.removeChild( this.lastChild);
}

which can be accepted by Firefox but IE 6 doesnot !!!
Doesnot IE support prototype define above DOM object?
Sound Un-resonable!
 
V

VK

I need to expand the DOM object function for conviniency as following:

Node.prototype.removeChildren = function() {
while( this.lastChild) this.removeChild( this.lastChild);
}

which can be accepted by Firefox but IE 6 doesnot !!!
Doesnot IE support prototype define above DOM object?
Sound Un-resonable!

Sounds very resonable to me because JavaScript != DOM and JavaScript
native methods != host objects methods.

Mozilla was able to implement this highly questionnable mixture because
their entire browser is implemented on JavaScript, including interface.
So it was not so difficult to add several extra bridges between the
engine and DOM tree.

A "highly questionnable mixture" because it seems confuse hell out of
developers as they missing the important difference between JavaScript
and DOM (based on posts in this group). So far no one tried yet to make
floating point math on say SPAN, but it may be just over the corner :)

The proper way to achieve what you are looking for is behavior (binding
by Mozilla).

You may start from here:
<http://msdn.microsoft.com/workshop/author/behaviors/overview.asp>
<http://www.mozilla.org/projects/xbl/xbl.html>
 
T

Thomas 'PointedEars' Lahn

VK said:
Sounds very resonable to me because JavaScript != DOM and JavaScript
native methods != host objects methods.

The explanation is correct, but it is not an explanation for this problem
at all.
Mozilla was able to implement this highly questionnable mixture because
their entire browser is implemented on JavaScript, including interface.
So it was not so difficult to add several extra bridges between the
engine and DOM tree.

Utter nonsense, as usual. Could you just hold your fingers still when you
have nothing intelligent to post? It would save a great deal of precious
bandwidth. TIA.

It works in Firefox because the Gecko DOM implements the Node interface
of the W3C DOM as a prototyped host object. That is not a questionable
design decision at all.
A "highly questionnable mixture" because it seems confuse hell out of ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
developers as they missing the important difference between JavaScript
and DOM (based on posts in this group).

(You call it that because your puny mind still cannot comprehend that
difference? I see.)

It does not work in IE yet because the IE DOM does no such thing yet.

The relevance of this fact regarding the fact that Gecko-based UAs implement
JavaScript (originally Netscape's, now Mozilla.org's ECMAScript
implementation) and IE-based UAs implement JScript (Microsoft's
ECMAScript implementation) as scripting language, equals _zero_.


PointedEars
 
Z

zhong.zx

Thomas 'PointedEars' Lahn 写é“:
The explanation is correct, but it is not an explanation for this problem
at all.


Utter nonsense, as usual. Could you just hold your fingers still when you
have nothing intelligent to post? It would save a great deal of precious
bandwidth. TIA.

It works in Firefox because the Gecko DOM implements the Node interface
of the W3C DOM as a prototyped host object. That is not a questionable
design decision at all.


(You call it that because your puny mind still cannot comprehend that
difference? I see.)

It does not work in IE yet because the IE DOM does no such thing yet.

The relevance of this fact regarding the fact that Gecko-based UAs implement
JavaScript (originally Netscape's, now Mozilla.org's ECMAScript
implementation) and IE-based UAs implement JScript (Microsoft's
ECMAScript implementation) as scripting language, equals _zero_.

Then, how to expand the DOM object function for IE instead of prototype
approach?
Is there anyway, such as encapsulating or something else, to implement
it?
Or no way at all?! If so, really bad :(
 
Z

zhong.zx

OK, thanks all answering to this question.

I have check this newgroup by searching with "dom prototype".
It cannot work out with IE DOM object of bingding prototype on it.
 
V

VK

I have check this newgroup by searching with "dom prototype".
It cannot work out with IE DOM object of bingding prototype on it.

You cannot make say "all HTML elements in this document have foobar()
method" in one assignment. But you can make say all div's in your
document draggable - in one assignment:

<style type="text/css"">
div {
behavior: url(draggable.htc);
/* for the exact link see MSDN link I gave you */
}
</style>

Pair with -moz-binding and you are done. Same way you can make say all
<address> block play music on click by default.

The medieval way is presented in two flawors:
The one you already know: create your own JavaScript objects with DOM
reference in it.

Another one is overload the constructor, so it would return the DOM
reference back after augmentation:

function xDIV(div) {
div.$ = this;
this.method1 = ...
this.method2 = ...
return div;
}
....
var d = document.createElement('DIV');
document.body.appendChild(new xDIV(d));

But it is indeed a medieval alchimie requiring manual node traversal
plus all neeeded and not needed code in one chunk.

As both bindings and behaviors are written in the conventiona
JavaScript/JScript I see no problem to use the recommended way.
 
R

Richard Cornford

I need to expand the DOM object function for conviniency
as following:

Node.prototype.removeChildren = function() {
while( this.lastChild) this.removeChild( this.lastChild);
}

which can be accepted by Firefox but IE 6 doesnot !!!
Doesnot IE support prototype define above DOM object?
Sound Un-resonable!

This would only sound unreasonable if you had good reasons to expect to
be able to modify the prototypes of host objects, which you don't, and
you could not trivially achieve the same outcome by some other means.

If you want to strip all the children from an element why not write a
global function for the task and pass the element as an argument to that
function?

function removeElementChildren(element){
var node;
while((node = element.lastChild)){
element.removeChild(node);
}
}

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top