<?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/"
xmlns:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: MooTools Class Creation&#160;Tips</title> <atom:link href="http://davidwalsh.name/mootools-class-tips/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/mootools-class-tips</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Thu, 09 Feb 2012 09:28:55 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3</generator> <item><title>By: Tim Wickstrom</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-26855</link> <dc:creator>Tim Wickstrom</dc:creator> <pubDate>Fri, 09 Sep 2011 16:55:02 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-26855</guid> <description>Have written dozens of classes over the last few years and today I was spinning my wheels while creating a new element and trying to access &#039;this&#039; as a reference to the element as well as bind(this) to access class methods and options....Thanks David for posting this have not used the self method in awhile and it was exactly what I was looking for!!!
var self = this; // .bind(this) on event functions obviously will not work!
new Element(&#039;li&#039;, {
html: this.markQuerySelection(r.title),
rel: this.liFocus+i,
styles: Object.merge({
&#039;background-color&#039;: (i%2?this.options.listEvenColor:this.options.listOddColor)
}, this.options.listItemStyles),
events: {
mouseover:function(e){
this.tween(&#039;background-color&#039;, &#039;#fffcb0&#039;)
},
mouseout: function(e) {
this.tween(&#039;background-color&#039;, (i%2?self.options.listEvenColor:self.options.listOddColor))
}
}
})</description> <content:encoded><![CDATA[<p>Have written dozens of classes over the last few years and today I was spinning my wheels while creating a new element and trying to access &#8216;this&#8217; as a reference to the element as well as bind(this) to access class methods and options&#8230;.</p><p>Thanks David for posting this have not used the self method in awhile and it was exactly what I was looking for!!!<br
/> var self = this; // .bind(this) on event functions obviously will not work!<br
/> new Element(&#8216;li&#8217;, {<br
/> html: this.markQuerySelection(r.title),<br
/> rel: this.liFocus+i,<br
/> styles: Object.merge({<br
/> &#8216;background-color&#8217;: (i%2?this.options.listEvenColor:this.options.listOddColor)<br
/> }, this.options.listItemStyles),<br
/> events: {<br
/> mouseover:function(e){<br
/> this.tween(&#8216;background-color&#8217;, &#8216;#fffcb0&#8242;)<br
/> },<br
/> mouseout: function(e) {<br
/> this.tween(&#8216;background-color&#8217;, (i%2?self.options.listEvenColor:self.options.listOddColor))<br
/> }<br
/> }<br
/> })</p> ]]></content:encoded> </item> <item><title>By: chris</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-22708</link> <dc:creator>chris</dc:creator> <pubDate>Sat, 12 Feb 2011 06:50:23 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-22708</guid> <description>thanks been punching myself dealing with the pitfalls of bind and found this how to, thanks, self rocks@!</description> <content:encoded><![CDATA[<p>thanks been punching myself dealing with the pitfalls of bind and found this how to, thanks, self rocks@!</p> ]]></content:encoded> </item> <item><title>By: MarkD</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-11739</link> <dc:creator>MarkD</dc:creator> <pubDate>Sat, 05 Sep 2009 21:18:06 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-11739</guid> <description>Isn&#039;t this closure solution (&#039;.self&#039; ) considered bad practice because of possible memory leaks escpecially in our good old friend ie6? Closures can be very powerful but they are quit tricky to handle.
For example you have to clean up the references yourself onBeforeUnload to prevent leaks?
Moo takes care of that when you use their method.</description> <content:encoded><![CDATA[<p>Isn&#8217;t this closure solution (&#8216;.self&#8217; ) considered bad practice because of possible memory leaks escpecially in our good old friend ie6? Closures can be very powerful but they are quit tricky to handle.<br
/> For example you have to clean up the references yourself onBeforeUnload to prevent leaks?<br
/> Moo takes care of that when you use their method.</p> ]]></content:encoded> </item> <item><title>By: Cohen</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-10682</link> <dc:creator>Cohen</dc:creator> <pubDate>Sat, 25 Jul 2009 17:28:20 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-10682</guid> <description>So what&#039;s the best choice of doing things?
- using bind (or the Binds mutator)
or ...
-  self (with the additional bonus you have access to &quot;this&quot; too)?The fundamental difference I think is that the self technique uses closures and the bind uses method encapsulation... so in theory the self is more performent...@kow: I am not sure I understand what you mean? Maybe you can give an example to clarify? If I understand correctly binding to this wouldn&#039;t be usefull outside of the &quot;first level&quot; either?</description> <content:encoded><![CDATA[<p>So what&#8217;s the best choice of doing things?<br
/> &#8211; using bind (or the Binds mutator)<br
/> or &#8230;<br
/> &#8211;  self (with the additional bonus you have access to &#8220;this&#8221; too)?</p><p>The fundamental difference I think is that the self technique uses closures and the bind uses method encapsulation&#8230; so in theory the self is more performent&#8230;</p><p>@kow: I am not sure I understand what you mean? Maybe you can give an example to clarify? If I understand correctly binding to this wouldn&#8217;t be usefull outside of the &#8220;first level&#8221; either?</p> ]]></content:encoded> </item> <item><title>By: kow</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-8664</link> <dc:creator>kow</dc:creator> <pubDate>Fri, 10 Apr 2009 16:18:38 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-8664</guid> <description>While this is very useful, keep in mind, that you only should use this where you need it, so on the first level, &#039;outside&#039; an inner function using self in unnecessary.</description> <content:encoded><![CDATA[<p>While this is very useful, keep in mind, that you only should use this where you need it, so on the first level, &#8216;outside&#8217; an inner function using self in unnecessary.</p> ]]></content:encoded> </item> <item><title>By: Chris</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-8234</link> <dc:creator>Chris</dc:creator> <pubDate>Mon, 16 Mar 2009 07:57:27 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-8234</guid> <description>var that = this;:D</description> <content:encoded><![CDATA[<p>var that = this;</p><p>:D</p> ]]></content:encoded> </item> <item><title>By: Jeremy Parrish</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-8150</link> <dc:creator>Jeremy Parrish</dc:creator> <pubDate>Tue, 10 Mar 2009 15:12:31 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-8150</guid> <description>Good tips. I like the &quot;self&quot; idea, but it seems like &quot;self&quot; could be a bad choice of names since it could be confused with the self/window object. I&#039;ve seen other people use a variable called &quot;that&quot; instead. As long as it&#039;s declared with the var keyword, it shouldn&#039;t be a problem, but it&#039;s still potentially confusing.</description> <content:encoded><![CDATA[<p>Good tips. I like the &#8220;self&#8221; idea, but it seems like &#8220;self&#8221; could be a bad choice of names since it could be confused with the self/window object. I&#8217;ve seen other people use a variable called &#8220;that&#8221; instead. As long as it&#8217;s declared with the var keyword, it shouldn&#8217;t be a problem, but it&#8217;s still potentially confusing.</p> ]]></content:encoded> </item> <item><title>By: Ryan</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-8149</link> <dc:creator>Ryan</dc:creator> <pubDate>Tue, 10 Mar 2009 13:58:00 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-8149</guid> <description>David,those are some great tips! I just found myself in a situation when writing a class where I used bind(this) but also needed to reference the element returned in the .each loop. Using self would have really made that easier.</description> <content:encoded><![CDATA[<p>David,</p><p>those are some great tips! I just found myself in a situation when writing a class where I used bind(this) but also needed to reference the element returned in the .each loop. Using self would have really made that easier.</p> ]]></content:encoded> </item> <item><title>By: Adriaan</title><link>http://davidwalsh.name/mootools-class-tips/comment-page-1#comment-8148</link> <dc:creator>Adriaan</dc:creator> <pubDate>Tue, 10 Mar 2009 13:45:50 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=1746#comment-8148</guid> <description>Thanks, this is quite useful.  I find that davidwalsh.name has almost become the defacto mootools site ;)</description> <content:encoded><![CDATA[<p>Thanks, this is quite useful.  I find that davidwalsh.name has almost become the defacto mootools site ;)</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching using disk: basic
Object Caching 800/801 objects using disk: basic

Served from: davidwalsh.name @ 2012-02-09 04:50:52 -->
