<?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: Retaining a reference, the simple way</title>
	<atom:link href="http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Floby</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-17935</link>
		<dc:creator>Floby</dc:creator>
		<pubDate>Sun, 09 Aug 2009 23:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-17935</guid>
		<description>what about this ?
&lt;pre lang=&quot;javascript&quot;&gt;
$( &#039;#something&#039; ).each( function(){
  $(this).width($(this).parent().innerWidth());
});
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>what about this ?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span class="br0">&#40;</span> <span class="st0">'#something'</span> <span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">width</span><span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">parent</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">innerWidth</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15512</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Thu, 02 Jul 2009 16:04:53 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15512</guid>
		<description>This is a fascinating study.

I used the &quot;Best Practices&quot; method today for something that looks like this:
&lt;pre lang=&quot;javascript&quot;&gt;
   $(&#039;#something&#039;).each(function(){
        var something = $(this);
        something.find(&#039;input&#039;).change(function(){
            myFunction(something);
        });
    });
&lt;/pre&gt;
I am curious as to whether the $_.this would work in this sort of application. Is the current value of $._this assigned permanently to the onchange, or would it use the value of $._this at the time the element was changed?</description>
		<content:encoded><![CDATA[<p>This is a fascinating study.</p>
<p>I used the &#8220;Best Practices&#8221; method today for something that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   $<span class="br0">&#40;</span><span class="st0">'#something'</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
        <span class="kw2">var</span> something <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span><span class="sy0">;</span>
        something.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">'input'</span><span class="br0">&#41;</span>.<span class="me1">change</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
            myFunction<span class="br0">&#40;</span>something<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>I am curious as to whether the $_.this would work in this sort of application. Is the current value of $._this assigned permanently to the onchange, or would it use the value of $._this at the time the element was changed?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15403</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 01 Jul 2009 06:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15403</guid>
		<description>@rafael; JavaScript is single threaded... Almost everything happens synchronously, one after the other... The value of &lt;code&gt;$._this&lt;/code&gt; will always equal the last selection you made. While this, as an idea, may be considered a bad practice in other languages, its usage in JavaScript does not present any issues. Like I&#039;ve said, the only time you would want to avoid this is when you make a selection outside of a callback function and then you wait for that callback function to fire.

Plus, to be honest, your argument is flawed since any variable is subject to change (except getters) - not just &lt;code&gt;$._this&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>@rafael; JavaScript is single threaded&#8230; Almost everything happens synchronously, one after the other&#8230; The value of <code>$._this</code> will always equal the last selection you made. While this, as an idea, may be considered a bad practice in other languages, its usage in JavaScript does not present any issues. Like I&#8217;ve said, the only time you would want to avoid this is when you make a selection outside of a callback function and then you wait for that callback function to fire.</p>
<p>Plus, to be honest, your argument is flawed since any variable is subject to change (except getters) &#8211; not just <code>$._this</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rafael bandeira</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15368</link>
		<dc:creator>rafael bandeira</dc:creator>
		<pubDate>Tue, 30 Jun 2009 17:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15368</guid>
		<description>this looks like bad design.
This is just the same as creating a global variable, and you know that there&#039;s no such thing as good/safe global variable.
You&#039;ll never be able to tell wether the $._this really contains that object at that given point, as I might change it anywhere on the code and it will reflect in any code using it.

Not a good practice at all.</description>
		<content:encoded><![CDATA[<p>this looks like bad design.<br />
This is just the same as creating a global variable, and you know that there&#8217;s no such thing as good/safe global variable.<br />
You&#8217;ll never be able to tell wether the $._this really contains that object at that given point, as I might change it anywhere on the code and it will reflect in any code using it.</p>
<p>Not a good practice at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15287</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 29 Jun 2009 13:48:01 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15287</guid>
		<description>@Steven, you raise a good point.. Using &lt;code&gt;$._this&lt;/code&gt; in callback functions would be a bad idea, as there&#039;s no telling what its value will be  by the time the callback fires.

I recommend only using it immediately after the selection; no functions involved. It&#039;s not an all-round problem solver; just a convenience-feature.</description>
		<content:encoded><![CDATA[<p>@Steven, you raise a good point.. Using <code>$._this</code> in callback functions would be a bad idea, as there&#8217;s no telling what its value will be  by the time the callback fires.</p>
<p>I recommend only using it immediately after the selection; no functions involved. It&#8217;s not an all-round problem solver; just a convenience-feature.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Black</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15285</link>
		<dc:creator>Steven Black</dc:creator>
		<pubDate>Mon, 29 Jun 2009 13:29:48 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15285</guid>
		<description>I could be wrong, but I suspect there may be issues here with animations --  stop() exists for the same reason -- and when $.ajax.async=true (which is the default).  

In other words, will $._this always be what we think it is?

We know a variable assignment is completely safe in this respect.</description>
		<content:encoded><![CDATA[<p>I could be wrong, but I suspect there may be issues here with animations &#8212;  stop() exists for the same reason &#8212; and when $.ajax.async=true (which is the default).  </p>
<p>In other words, will $._this always be what we think it is?</p>
<p>We know a variable assignment is completely safe in this respect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15269</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 29 Jun 2009 06:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15269</guid>
		<description>@Valentino, you could rename it to &lt;code&gt;$.current&lt;/code&gt; or anything really...

@tfforums, Yes you could, but that&#039;s long-winded and gets quite annoying after a while.</description>
		<content:encoded><![CDATA[<p>@Valentino, you could rename it to <code>$.current</code> or anything really&#8230;</p>
<p>@tfforums, Yes you could, but that&#8217;s long-winded and gets quite annoying after a while.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tfforums</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15257</link>
		<dc:creator>tfforums</dc:creator>
		<pubDate>Mon, 29 Jun 2009 02:00:02 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15257</guid>
		<description>coudln&#039;t you just do this with .each() ie:

$( &#039;#something&#039; ).each($(this).width( $(this).parent().innerWidth() )); ??</description>
		<content:encoded><![CDATA[<p>coudln&#8217;t you just do this with .each() ie:</p>
<p>$( &#8216;#something&#8217; ).each($(this).width( $(this).parent().innerWidth() )); ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentino</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15220</link>
		<dc:creator>Valentino</dc:creator>
		<pubDate>Sun, 28 Jun 2009 12:14:11 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15220</guid>
		<description>wow! that&#039;s great! I only complain about the underscore in &quot;_this&quot;. it&#039;s not really jQuery-style.. ;)</description>
		<content:encoded><![CDATA[<p>wow! that&#8217;s great! I only complain about the underscore in &#8220;_this&#8221;. it&#8217;s not really jQuery-style.. <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeferson Koslowski</title>
		<link>http://james.padolsey.com/javascript/retaining-a-reference-the-simple-way/comment-page-1/#comment-15177</link>
		<dc:creator>Jeferson Koslowski</dc:creator>
		<pubDate>Sat, 27 Jun 2009 22:10:50 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=972#comment-15177</guid>
		<description>Lol, I faced this problem yesterday and adopted the &quot;best practice&quot; solution you mentioned, although I didn&#039;t liked it.

Would be great to have something like this implemented in jQuery core.</description>
		<content:encoded><![CDATA[<p>Lol, I faced this problem yesterday and adopted the &#8220;best practice&#8221; solution you mentioned, although I didn&#8217;t liked it.</p>
<p>Would be great to have something like this implemented in jQuery core.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

