<?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: Prototyping JavaScript objects functionally using jQuery and JSON</title>
	<atom:link href="http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/</link>
	<description>Web-developing, PC game playing, fast driving and not sleeping geek grad student...</description>
	<lastBuildDate>Tue, 13 Dec 2011 14:10:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: John</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-1243</link>
		<dc:creator>John</dc:creator>
		<pubDate>Sun, 29 May 2011 18:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-1243</guid>
		<description>Very fascinating comment, Kirk. I&#039;ve used this method of OO implementation many many times but never ran one of the generated objects against &#039;instanceof&#039;.

You have officially kicked off a weekend full of research and experimentation; I&#039;ll certainly let you know what I come up with.

Thanks again!</description>
		<content:encoded><![CDATA[<p>Very fascinating comment, Kirk. I&#8217;ve used this method of OO implementation many many times but never ran one of the generated objects against &#8216;instanceof&#8217;.</p>
<p>You have officially kicked off a weekend full of research and experimentation; I&#8217;ll certainly let you know what I come up with.</p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirk</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-1234</link>
		<dc:creator>Kirk</dc:creator>
		<pubDate>Wed, 25 May 2011 22:40:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-1234</guid>
		<description>John,

This was an interesting approach.  Thanks for sharing.  Like you, I&#039;ve been searching for a better method of implementing OO techniques in Javascript.  I&#039;ve done a lot of reading and tried a number of different approaches.  I thought I had my own version working nearly perfectly until today.  Most of my work was based off a combination of these articles:
http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html
http://blog.reinpetersen.com/2008/10/interface-in-javascript.html

However, today as I was implementing something with jQuery&#039;s $.ajax() method, I discovered to my chagrin that extending Object.prototype does not play well with jQuery.  In particular, while using $.ajax(), jQuery will do a &quot;for..in&quot; over the data object and pass each of its properties as data in your ajax request.  If the properties are functions, they will be executed and their results will be passed as parameters.  It would be nice if jQuery would bother to check the properties against Object.hasOwnProperty(), but unfortunately it doesn&#039;t.

This obviously introduced a couple of problems.  The first was that the Object.prototype methods suggested on that link were throwing errors because jQuery was calling them without the expected parameters.  If a user did something wrong like that, throwing an error would be the proper response, but when jQuery was doing it, it was a problem.  I was able to correct this by doing some more checking on the arguments passed, and by removing a couple of the less important &quot;throw&quot; statements.

However, the problem that wouldn&#039;t go away was the fact that my AJAX requests were sending more data than they should (and much of it was irrelevant).  For example, even if I tried to make an AJAX request with a single object literal containing a single property, jQuery would add properties for the execution results of calling Object.inherits(), Object.implements(), etc., for that object literal.  It was a waste of execution cycles and data over the wire.

I searched for &quot;jQuery OO Javascript&quot; and stumbled upon your method here, and gave it a try.  It seems promising, but as I was playing with your example, I noticed something that would be a deal breaker for me.  I copied all of your code from this page and ran it.  Things seemed to work as expected, running parent methods with .inherited(), etc.  However, something like this unfortunately returned false:

box instanceof window.foo

Part of the appeal of applying OO concepts to Javascript is to be able to decisively alter execution logic or verify parameters based on the class of an object, so to me this would be a fundamental necessity.  I haven&#039;t spent much time poring over your code yet to see how it might be possible to modify it so that instanceof could be used as expected, but I&#039;d be curious to hear if you had any thoughts about it.

If nothing else, this is a good mental exercise and is an academically interesting thing for me to see.  Thanks again for sharing it!</description>
		<content:encoded><![CDATA[<p>John,</p>
<p>This was an interesting approach.  Thanks for sharing.  Like you, I&#8217;ve been searching for a better method of implementing OO techniques in Javascript.  I&#8217;ve done a lot of reading and tried a number of different approaches.  I thought I had my own version working nearly perfectly until today.  Most of my work was based off a combination of these articles:<br />
<a href="http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html" rel="nofollow">http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html</a><br />
<a href="http://blog.reinpetersen.com/2008/10/interface-in-javascript.html" rel="nofollow">http://blog.reinpetersen.com/2008/10/interface-in-javascript.html</a></p>
<p>However, today as I was implementing something with jQuery&#8217;s $.ajax() method, I discovered to my chagrin that extending Object.prototype does not play well with jQuery.  In particular, while using $.ajax(), jQuery will do a &#8220;for..in&#8221; over the data object and pass each of its properties as data in your ajax request.  If the properties are functions, they will be executed and their results will be passed as parameters.  It would be nice if jQuery would bother to check the properties against Object.hasOwnProperty(), but unfortunately it doesn&#8217;t.</p>
<p>This obviously introduced a couple of problems.  The first was that the Object.prototype methods suggested on that link were throwing errors because jQuery was calling them without the expected parameters.  If a user did something wrong like that, throwing an error would be the proper response, but when jQuery was doing it, it was a problem.  I was able to correct this by doing some more checking on the arguments passed, and by removing a couple of the less important &#8220;throw&#8221; statements.</p>
<p>However, the problem that wouldn&#8217;t go away was the fact that my AJAX requests were sending more data than they should (and much of it was irrelevant).  For example, even if I tried to make an AJAX request with a single object literal containing a single property, jQuery would add properties for the execution results of calling Object.inherits(), Object.implements(), etc., for that object literal.  It was a waste of execution cycles and data over the wire.</p>
<p>I searched for &#8220;jQuery OO Javascript&#8221; and stumbled upon your method here, and gave it a try.  It seems promising, but as I was playing with your example, I noticed something that would be a deal breaker for me.  I copied all of your code from this page and ran it.  Things seemed to work as expected, running parent methods with .inherited(), etc.  However, something like this unfortunately returned false:</p>
<p>box instanceof window.foo</p>
<p>Part of the appeal of applying OO concepts to Javascript is to be able to decisively alter execution logic or verify parameters based on the class of an object, so to me this would be a fundamental necessity.  I haven&#8217;t spent much time poring over your code yet to see how it might be possible to modify it so that instanceof could be used as expected, but I&#8217;d be curious to hear if you had any thoughts about it.</p>
<p>If nothing else, this is a good mental exercise and is an academically interesting thing for me to see.  Thanks again for sharing it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-28</link>
		<dc:creator>John</dc:creator>
		<pubDate>Sun, 21 Mar 2010 00:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-28</guid>
		<description>@Marcus Dalgren:
Yes, my apologies, I neglected to mention I was using the jquery-getobject plugin. I had originally written my own setObject but why create &amp; maintain something already in existence?

I&#039;ll update the post to reflect the inclusion of jquery-getobject.

Thanks.</description>
		<content:encoded><![CDATA[<p>@Marcus Dalgren:<br />
Yes, my apologies, I neglected to mention I was using the jquery-getobject plugin. I had originally written my own setObject but why create &amp; maintain something already in existence?</p>
<p>I&#8217;ll update the post to reflect the inclusion of jquery-getobject.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-27</link>
		<dc:creator>John</dc:creator>
		<pubDate>Sun, 21 Mar 2010 00:14:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-27</guid>
		<description>@James Burke:
That&#039;s rather interesting. I didn&#039;t look into Dojo at all as I worked on this, but you&#039;re right there are lots of similarities.</description>
		<content:encoded><![CDATA[<p>@James Burke:<br />
That&#8217;s rather interesting. I didn&#8217;t look into Dojo at all as I worked on this, but you&#8217;re right there are lots of similarities.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus Dalgren</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-6</link>
		<dc:creator>Marcus Dalgren</dc:creator>
		<pubDate>Sun, 07 Mar 2010 03:07:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-6</guid>
		<description>Hello!

I tried out your declare function because the idea really appeals to me but when I try to use it I get the error $.setObject is not a function.
Is this supposed to be a method native to jQuery or did you miss putting that method in the code?
I noticed that line 113 is the only place setObject is used and it isn&#039;t declared anywhere in the code.
When I googled jQuery setobject I found this: http://benalman.com/code/projects/jquery-getobject/docs/files/jquery-ba-getobject-js.html am I supposed to load that first?

Any help would be very appreciated since I think this is an awesome idea and I also dig the PHP like syntax.

Kindly,
Marcus</description>
		<content:encoded><![CDATA[<p>Hello!</p>
<p>I tried out your declare function because the idea really appeals to me but when I try to use it I get the error $.setObject is not a function.<br />
Is this supposed to be a method native to jQuery or did you miss putting that method in the code?<br />
I noticed that line 113 is the only place setObject is used and it isn&#8217;t declared anywhere in the code.<br />
When I googled jQuery setobject I found this: <a href="http://benalman.com/code/projects/jquery-getobject/docs/files/jquery-ba-getobject-js.html" rel="nofollow">http://benalman.com/code/projects/jquery-getobject/docs/files/jquery-ba-getobject-js.html</a> am I supposed to load that first?</p>
<p>Any help would be very appreciated since I think this is an awesome idea and I also dig the PHP like syntax.</p>
<p>Kindly,<br />
Marcus</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Burke</title>
		<link>http://blog.johngauthier.com/2010/02/26/prototyping-javascript-objects-functionally-using-jquery-and-json/comment-page-1/#comment-5</link>
		<dc:creator>James Burke</dc:creator>
		<pubDate>Fri, 05 Mar 2010 00:56:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.johngauthier.com/?p=47#comment-5</guid>
		<description>This looks a lot like Dojo&#039;s declare:
http://dojotoolkit.org/reference-guide/dojo/declare.html</description>
		<content:encoded><![CDATA[<p>This looks a lot like Dojo&#8217;s declare:<br />
<a href="http://dojotoolkit.org/reference-guide/dojo/declare.html" rel="nofollow">http://dojotoolkit.org/reference-guide/dojo/declare.html</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

