<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Make the XHR abstraction shorter</title>
	<atom:link href="http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Dustin Diaz</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249717</link>
		<dc:creator>Dustin Diaz</dc:creator>
		<pubDate>Mon, 23 Apr 2007 20:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249717</guid>
		<description>This still does detection on every request. Why not branch at load?</description>
		<content:encoded><![CDATA[<p>This still does detection on every request. Why not branch at load?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel Benevides</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249618</link>
		<dc:creator>Miguel Benevides</dc:creator>
		<pubDate>Fri, 20 Apr 2007 02:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249618</guid>
		<description>;) Klaus</description>
		<content:encoded><![CDATA[<p>;) Klaus</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Klaus Hartl</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249614</link>
		<dc:creator>Klaus Hartl</dc:creator>
		<pubDate>Thu, 19 Apr 2007 23:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249614</guid>
		<description>Interesting. jQuery does the following since the early days:

&lt;code&gt;if ( !window.XMLHttpRequest )
	XMLHttpRequest = function(){
		return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
	};&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Interesting. jQuery does the following since the early days:</p>
<p><code>if ( !window.XMLHttpRequest )<br />
	XMLHttpRequest = function(){<br />
		return new ActiveXObject("Microsoft.XMLHTTP");<br />
	};</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Wubben</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249606</link>
		<dc:creator>Mark Wubben</dc:creator>
		<pubDate>Thu, 19 Apr 2007 18:01:33 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249606</guid>
		<description>Elad, yes, that works. It doesn&#039;t change the example posted here though :)</description>
		<content:encoded><![CDATA[<p>Elad, yes, that works. It doesn&#8217;t change the example posted here though :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249573</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 19 Apr 2007 03:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249573</guid>
		<description>@Kris - Why don&#039;t you just disable Firebug for Ajaxian?  I&#039;m not even sure why you&#039;re using it during regular browsing, in my experience it just slows things down.  I keep it disabled and only turn it on when I explicitly need it.</description>
		<content:encoded><![CDATA[<p>@Kris &#8211; Why don&#8217;t you just disable Firebug for Ajaxian?  I&#8217;m not even sure why you&#8217;re using it during regular browsing, in my experience it just slows things down.  I keep it disabled and only turn it on when I explicitly need it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elad Ossadon</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249567</link>
		<dc:creator>Elad Ossadon</dc:creator>
		<pubDate>Wed, 18 Apr 2007 19:43:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249567</guid>
		<description>@Mark - that&#039;s because new operator returns the object itself, which is not 1 but an instance of the function, regardless the &#039;return&#039; statement.
To achieve that kind of syntax, you should override the &lt;b&gt;valueOf&lt;/b&gt; method, like this:
&lt;code&gt;
function GetFive() {}
GetFive.prototype.valueOf=function () { return 5; }
alert(5*new GetFive());&lt;/code&gt;
(very similar like overriding the toString method).</description>
		<content:encoded><![CDATA[<p>@Mark &#8211; that&#8217;s because new operator returns the object itself, which is not 1 but an instance of the function, regardless the &#8216;return&#8217; statement.<br />
To achieve that kind of syntax, you should override the <b>valueOf</b> method, like this:<br />
<code><br />
function GetFive() {}<br />
GetFive.prototype.valueOf=function () { return 5; }<br />
alert(5*new GetFive());</code><br />
(very similar like overriding the toString method).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249561</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Wed, 18 Apr 2007 18:19:39 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249561</guid>
		<description>@Kris Zyp,

Um... I&#039;ve never had Firefox/Firebug generate an error using Prototype, nor accessing its Ajax object. Not once.</description>
		<content:encoded><![CDATA[<p>@Kris Zyp,</p>
<p>Um&#8230; I&#8217;ve never had Firefox/Firebug generate an error using Prototype, nor accessing its Ajax object. Not once.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Wubben</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249557</link>
		<dc:creator>Mark Wubben</dc:creator>
		<pubDate>Wed, 18 Apr 2007 16:16:19 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249557</guid>
		<description>@Jonathan, I get this in Firefox:

new function(){return 1} -&gt; [object Object]

5 * (new function(){return 1}) -&gt; NaN</description>
		<content:encoded><![CDATA[<p>@Jonathan, I get this in Firefox:</p>
<p>new function(){return 1} -&gt; [object Object]</p>
<p>5 * (new function(){return 1}) -&gt; NaN</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicolas Faugout</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249556</link>
		<dc:creator>Nicolas Faugout</dc:creator>
		<pubDate>Wed, 18 Apr 2007 16:09:17 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249556</guid>
		<description>@Elad - I owe you one! I didn&#039;t know IE was reading the script AND assigning functions as it discovers them even neasted in the code. Your version of course solves the IE 7 issue.</description>
		<content:encoded><![CDATA[<p>@Elad &#8211; I owe you one! I didn&#8217;t know IE was reading the script AND assigning functions as it discovers them even neasted in the code. Your version of course solves the IE 7 issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris Zyp</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249554</link>
		<dc:creator>Kris Zyp</dc:creator>
		<pubDate>Wed, 18 Apr 2007 15:47:28 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249554</guid>
		<description>I really appreciate staying away from prototype&#039;s ridiculous try/catch technique. It triggers firebug because there is an error for each XHR request. I only visit Ajaxian with IE because of that.</description>
		<content:encoded><![CDATA[<p>I really appreciate staying away from prototype&#8217;s ridiculous try/catch technique. It triggers firebug because there is an error for each XHR request. I only visit Ajaxian with IE because of that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elad Ossadon</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249551</link>
		<dc:creator>Elad Ossadon</dc:creator>
		<pubDate>Wed, 18 Apr 2007 14:57:04 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249551</guid>
		<description>@Nicolas - That&#039;s bad programming, relying on a logical error, even if it works. Besides, like @Jonathan said, it&#039;ll overwrite IE7&#039;s native object.

If it wasn&#039;t the XMLHttpRequest, or &quot;else&quot; clause would&#039;ve been written, as I mentioned in my code - the two browsers would present different results.

You can put a bit more characters and make it work as it should be and still maintaining the &#039;good programming&#039;, by asking for &#039;window.XMLHttpRequest&#039; and assigning to it.

&lt;code&gt;
if (!window.XMLHttpRequest) {
  window.XMLHttpRequest=function () {
    return new ActiveXObject(&#039;Microsoft.XMLHTTP&#039;);
  }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Nicolas &#8211; That&#8217;s bad programming, relying on a logical error, even if it works. Besides, like @Jonathan said, it&#8217;ll overwrite IE7&#8242;s native object.</p>
<p>If it wasn&#8217;t the XMLHttpRequest, or &#8220;else&#8221; clause would&#8217;ve been written, as I mentioned in my code &#8211; the two browsers would present different results.</p>
<p>You can put a bit more characters and make it work as it should be and still maintaining the &#8216;good programming&#8217;, by asking for &#8216;window.XMLHttpRequest&#8217; and assigning to it.</p>
<p><code><br />
if (!window.XMLHttpRequest) {<br />
  window.XMLHttpRequest=function () {<br />
    return new ActiveXObject('Microsoft.XMLHTTP');<br />
  }<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicolas Faugout</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249544</link>
		<dc:creator>Nicolas Faugout</dc:creator>
		<pubDate>Wed, 18 Apr 2007 14:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249544</guid>
		<description>A little explaination on my code :
- Elad, I don&#039;t see any incompatibility between what you say and my code. Think about the !XMLHttpRequest beeing here for FF not to redefine XMlHttpRequest.
As for IE, if the function is declared during the reading process you described, that&#039;s great, because it is what we want on IE ;)
- Kae, I agree with you, this code need some diggin

What I wanted to introduce, after the if then else checking browser version stuff and the magic try/catch Prototype solution is a new approach that would consist of defining once for all (at run time) a function named XMLHttpRequest in order not to introduce a new name for instanciating AJAX calls (when not using any framework of course).
Feel free to adapt the idea to your needs (several ActiveXObject uses, etc..)</description>
		<content:encoded><![CDATA[<p>A little explaination on my code :<br />
- Elad, I don&#8217;t see any incompatibility between what you say and my code. Think about the !XMLHttpRequest beeing here for FF not to redefine XMlHttpRequest.<br />
As for IE, if the function is declared during the reading process you described, that&#8217;s great, because it is what we want on IE ;)<br />
- Kae, I agree with you, this code need some diggin</p>
<p>What I wanted to introduce, after the if then else checking browser version stuff and the magic try/catch Prototype solution is a new approach that would consist of defining once for all (at run time) a function named XMLHttpRequest in order not to introduce a new name for instanciating AJAX calls (when not using any framework of course).<br />
Feel free to adapt the idea to your needs (several ActiveXObject uses, etc..)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eugene a</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249543</link>
		<dc:creator>eugene a</dc:creator>
		<pubDate>Wed, 18 Apr 2007 13:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249543</guid>
		<description>this is what i use
its in the constructor of the core ajax &quot;query&quot; class

//--------------------------------------------------------------
// constructor
//--------------------------------------------------------------
this.setGlobals = function(){
	if(window.ActiveXObject){isIE = true;}
	objREQ = isIE == false ? new XMLHttpRequest() : new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;) ;
	my_AJAX = this;
}</description>
		<content:encoded><![CDATA[<p>this is what i use<br />
its in the constructor of the core ajax &#8220;query&#8221; class</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
// constructor<br />
//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
this.setGlobals = function(){<br />
	if(window.ActiveXObject){isIE = true;}<br />
	objREQ = isIE == false ? new XMLHttpRequest() : new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;) ;<br />
	my_AJAX = this;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elad Ossadon</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249542</link>
		<dc:creator>Elad Ossadon</dc:creator>
		<pubDate>Wed, 18 Apr 2007 13:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249542</guid>
		<description>Some assumptions you might have taken, but are wrong:

On IE6, &lt;code&gt;!XMLHttpRequest&lt;/code&gt; &lt;em&gt;doesn&#039;t&lt;/em&gt; return false here.
That&#039;s because IE reads the &quot;function&quot;s on the page before running thru the code. It means, it reads the code, finds all the functions and makes the 

functions list for the current scope. When it gets to &quot;function XMLHttpRequest&quot; it defines window[&quot;XMLHttpRequest&quot;]=function () { ... } (window is the 

current scope). Only THEN, after declaring the functions, it goes thru the whole code from line 1.

This is NOT true for Gecko.
&lt;code&gt;
function a() {
	alert(&quot;a&quot;);
}
if (false) function a() {
	alert(&quot;b&quot;);
}
a();
&lt;/code&gt;
In the above code, IE will shout &quot;b&quot;, and FF will shout &quot;a&quot;. That is because what I explained before.
Accessing to a() is available before &quot;function a()&quot; is declared, and IE takes the LAST declaration no matter where it is (assuming it&#039;s in the same scope).
FF declares the if statement as scoped statement.
The following code will explain:
&lt;code&gt;
a();

if (true) {
	function a() {
		alert(&quot;a&quot;);
	}
	a();
}
function a() {
	alert(&quot;b&quot;);
}
&lt;/code&gt;
For FF, the result is &quot;b&quot;, &quot;a&quot;.
For IE6, it&#039;s &quot;b&quot;, &quot;b&quot;.

On IE then, the !XMLHttpRequest returns TRUE because it is declared.
FF ignores the statement because XMLHttpRequest does exist and as mentioned before, doesn&#039;t declares &quot;function XMLHttpRequest&quot; as a functions.

BTW, declaring &quot;f=function ()&quot; is different than &quot;function f()&quot;. The latter is accessible from everywhere in the same scope, unlike the first that accessible only after being declared.</description>
		<content:encoded><![CDATA[<p>Some assumptions you might have taken, but are wrong:</p>
<p>On IE6, <code>!XMLHttpRequest</code> <em>doesn&#8217;t</em> return false here.<br />
That&#8217;s because IE reads the &#8220;function&#8221;s on the page before running thru the code. It means, it reads the code, finds all the functions and makes the </p>
<p>functions list for the current scope. When it gets to &#8220;function XMLHttpRequest&#8221; it defines window["XMLHttpRequest"]=function () { &#8230; } (window is the </p>
<p>current scope). Only THEN, after declaring the functions, it goes thru the whole code from line 1.</p>
<p>This is NOT true for Gecko.<br />
<code><br />
function a() {<br />
	alert("a");<br />
}<br />
if (false) function a() {<br />
	alert("b");<br />
}<br />
a();<br />
</code><br />
In the above code, IE will shout &#8220;b&#8221;, and FF will shout &#8220;a&#8221;. That is because what I explained before.<br />
Accessing to a() is available before &#8220;function a()&#8221; is declared, and IE takes the LAST declaration no matter where it is (assuming it&#8217;s in the same scope).<br />
FF declares the if statement as scoped statement.<br />
The following code will explain:<br />
<code><br />
a();</p>
<p>if (true) {<br />
	function a() {<br />
		alert("a");<br />
	}<br />
	a();<br />
}<br />
function a() {<br />
	alert("b");<br />
}<br />
</code><br />
For FF, the result is &#8220;b&#8221;, &#8220;a&#8221;.<br />
For IE6, it&#8217;s &#8220;b&#8221;, &#8220;b&#8221;.</p>
<p>On IE then, the !XMLHttpRequest returns TRUE because it is declared.<br />
FF ignores the statement because XMLHttpRequest does exist and as mentioned before, doesn&#8217;t declares &#8220;function XMLHttpRequest&#8221; as a functions.</p>
<p>BTW, declaring &#8220;f=function ()&#8221; is different than &#8220;function f()&#8221;. The latter is accessible from everywhere in the same scope, unlike the first that accessible only after being declared.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Pascarello</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249534</link>
		<dc:creator>Eric Pascarello</dc:creator>
		<pubDate>Wed, 18 Apr 2007 11:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249534</guid>
		<description>There is a reason behind using the try catch other than determining version suport:
http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html</description>
		<content:encoded><![CDATA[<p>There is a reason behind using the try catch other than determining version suport:<br />
<a href="http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html" rel="nofollow">http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Wubben</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249533</link>
		<dc:creator>Mark Wubben</dc:creator>
		<pubDate>Wed, 18 Apr 2007 11:45:42 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249533</guid>
		<description>Returning from a constructor is not exactly something you&#039;re supposed to do. It might work in IE, but it won&#039;t work in other browsers.</description>
		<content:encoded><![CDATA[<p>Returning from a constructor is not exactly something you&#8217;re supposed to do. It might work in IE, but it won&#8217;t work in other browsers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kae Verens</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249531</link>
		<dc:creator>Kae Verens</dc:creator>
		<pubDate>Wed, 18 Apr 2007 11:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249531</guid>
		<description>/me looks at date - nope, the 1st has been well gone.

why is this news? the try/catch thing used by most frameworks is because Microsoft.XMLHTTP is not always available (depends on the version of MSXML, or something).

by removing the other versions, you will be restricting your IE audience.</description>
		<content:encoded><![CDATA[<p>/me looks at date &#8211; nope, the 1st has been well gone.</p>
<p>why is this news? the try/catch thing used by most frameworks is because Microsoft.XMLHTTP is not always available (depends on the version of MSXML, or something).</p>
<p>by removing the other versions, you will be restricting your IE audience.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan</title>
		<link>http://ajaxian.com/archives/make-the-xhr-abstraction-shorter/comment-page-1#comment-249529</link>
		<dc:creator>Jordan</dc:creator>
		<pubDate>Wed, 18 Apr 2007 10:44:45 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=2323#comment-249529</guid>
		<description>This is so neat! Expect jQuery and MochiKit to be pouncing on this and adding it to their library.</description>
		<content:encoded><![CDATA[<p>This is so neat! Expect jQuery and MochiKit to be pouncing on this and adding it to their library.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

