prototype = new XMLHttpRequest()? why not?

P

Piotr K

Ok, all over the internet people are creating "wrapper" object over
XMLHttpRequest rather then prototyping it and I wonder why, are there
any drawbacks for this method? I couldn't find much info about it on
google..

Thanks for replies
 
H

Helbrax

Ok, all over the internet people are creating "wrapper" object over
XMLHttpRequest rather then prototyping it and I wonder why, are there
any drawbacks for this method? I couldn't find much info about it on
google..

Thanks for replies

I don't think IE6 will allow you to protoype the xmlhttprequest
object. I don't know about IE7's native object.
 
J

Joost Diepenmaat

Helbrax said:
I don't think IE6 will allow you to protoype the xmlhttprequest
object. I don't know about IE7's native object.

It's worse than that: IE6 doesn't even /have/ an XMLHttpRequest object
as a property of the global object. IOW, there isn't anything to
"prototype". And looking at IE behaviour for other host objects, it's
doubtful you can usefully extend XMLHttpRequest's prototype on IE7,
though I haven't tried it.
 
L

Lasse Reichstein Nielsen

Piotr K said:
Ok, all over the internet people are creating "wrapper" object over
XMLHttpRequest rather then prototyping it and I wonder why, are there
any drawbacks for this method?

Apart from technical problems, inheriting from an object means that
you expose the methods of that object along with what you add.
If you want to create an easier interface to use, you would want to
only expose that interface, and hide the internal workings of the
XMLHTTPRequest object from the unsuspecting user.

It's a guideline in, e.g., Java: favor composition over inheritance.
(In C++, it would probably be: favor composition over public inheritance).

You don't want to *be* an XMLHTTPRequest, you just want to *use* one.

/L
 
T

Thomas 'PointedEars' Lahn

Piotr said:
Ok, all over the internet people are creating "wrapper" object over
XMLHttpRequest rather then prototyping it and I wonder why,
are there any drawbacks for this method?

Good question!

The object does not expose a public `prototype' property in all
implementations. It does in the Gecko DOM, Apple WebCore and the Opera
(9.x) DOM. It does not in the MSHTML DOM.

Also note that there was no public XHR constructor in MSHTML before version
7, you have to create the XHR object with ActiveXObject() there.

So prototyping XHR has the obvious drawback that it does not work everywhere
where XHR is supported, especially not in the reference implementation of
MSHTML. And there is no point in doing something different for another UA
when you can write your own interface and have it consistent among UAs.

Other than that, I don't buy the arguments made around here; an XHR object
that could be prototyped would not be a bad idea; probably that is what the
other implementors thought.


HTH

PointedEars
 

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

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top