<?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: Playing with CoffeeScript</title>
	<atom:link href="http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/</link>
	<description>Korny&#039;s tech blog</description>
	<lastBuildDate>Sat, 04 Jun 2011 05:58:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Billy Moon</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-40</link>
		<dc:creator>Billy Moon</dc:creator>
		<pubDate>Fri, 11 Mar 2011 19:17:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-40</guid>
		<description>I also figured out a way to get coffee script to work inline within the page&#039;s javascript.

Forums suggest some concern about compatibility with some old browsers - I have not tested them all.

Main benefit I am looking at is to be able to use coffee script to build complex data objects, or anywhere else where it seems more convenient, and still have the ability to jump back into javascript/jQuery where I can copy and paste code from millions of forums.

This is not the recommended method for implementation - where a compiled source is more appropriate, but very nice for development.

Example of inline CoffeeScript: http://pastebin.com/CkgCvqcR</description>
		<content:encoded><![CDATA[<p>I also figured out a way to get coffee script to work inline within the page&#8217;s javascript.</p>
<p>Forums suggest some concern about compatibility with some old browsers &#8211; I have not tested them all.</p>
<p>Main benefit I am looking at is to be able to use coffee script to build complex data objects, or anywhere else where it seems more convenient, and still have the ability to jump back into javascript/jQuery where I can copy and paste code from millions of forums.</p>
<p>This is not the recommended method for implementation &#8211; where a compiled source is more appropriate, but very nice for development.</p>
<p>Example of inline CoffeeScript: <a href="http://pastebin.com/CkgCvqcR" rel="nofollow">http://pastebin.com/CkgCvqcR</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billy Moon</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-39</link>
		<dc:creator>Billy Moon</dc:creator>
		<pubDate>Fri, 11 Mar 2011 18:24:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-39</guid>
		<description>I love the article - I was just starting the same learning curve as I came across this artcle. I only heard about Raphael yesterday, and coffeescript today - so it was a perfect way to try to get familiar with them both.

I read through the comments, and I tried to implement some of the ideas. I used @ where I could, and got rid of tons of brackets. I also used the fat arrows for the click handlers so that the @ does not get lost in the $ object. I am sure it can be slimmed down more - but I am quite impressed with how clean it looks now compared to how it started off!

Here is the slimmed down version: http://pastebin.com/tdMLsXUB

Keep up the good work!</description>
		<content:encoded><![CDATA[<p>I love the article &#8211; I was just starting the same learning curve as I came across this artcle. I only heard about Raphael yesterday, and coffeescript today &#8211; so it was a perfect way to try to get familiar with them both.</p>
<p>I read through the comments, and I tried to implement some of the ideas. I used @ where I could, and got rid of tons of brackets. I also used the fat arrows for the click handlers so that the @ does not get lost in the $ object. I am sure it can be slimmed down more &#8211; but I am quite impressed with how clean it looks now compared to how it started off!</p>
<p>Here is the slimmed down version: <a href="http://pastebin.com/tdMLsXUB" rel="nofollow">http://pastebin.com/tdMLsXUB</a></p>
<p>Keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jashkenas</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-34</link>
		<dc:creator>jashkenas</dc:creator>
		<pubDate>Fri, 26 Feb 2010 20:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-34</guid>
		<description>Right -- when you pass the &quot;app.init&quot; function into jQuery (binding it to document.ready), you&#039;re pulling the function off of the &quot;app&quot; object, and it loses its sense of &quot;this&quot;. So, another way to go is to keep your single init, and replace the final line with this:

$(-&gt; app.init())</description>
		<content:encoded><![CDATA[<p>Right &#8212; when you pass the &#8220;app.init&#8221; function into jQuery (binding it to document.ready), you&#8217;re pulling the function off of the &#8220;app&#8221; object, and it loses its sense of &#8220;this&#8221;. So, another way to go is to keep your single init, and replace the final line with this:</p>
<p>$(-&gt; app.init())</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: korny</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-33</link>
		<dc:creator>korny</dc:creator>
		<pubDate>Fri, 26 Feb 2010 00:06:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-33</guid>
		<description>In fact, I can clean everything up by putting in a second init, and then I can use &#039;@&#039; (which is an alias for &#039;this.&#039;
&lt;code&gt;
app: {
   init: -&gt; app.__init()
   __init:
     @paper: Raphael(&#039;playspace&#039;,320,200)
     @draw_circle()
     @draw_square()
&lt;/code&gt;
Nice!</description>
		<content:encoded><![CDATA[<p>In fact, I can clean everything up by putting in a second init, and then I can use &#8216;@&#8217; (which is an alias for &#8216;this.&#8217;<br />
<code><br />
app: {<br />
   init: -&gt; app.__init()<br />
   __init:<br />
     @paper: Raphael('playspace',320,200)<br />
     @draw_circle()<br />
     @draw_square()<br />
</code><br />
Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: korny</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-32</link>
		<dc:creator>korny</dc:creator>
		<pubDate>Fri, 26 Feb 2010 00:02:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-32</guid>
		<description>Thanks - that works!
I&#039;m still confused around how &#039;this&#039; works - it&#039;s not really a Coffeescript thing, more of a Javascript thing.
For example, in my code above, I can change references in &#039;app.draw_circle&#039; to use &#039;this&#039; and they get &#039;app&#039;.  Which makes sense, as they are called as &#039;app.draw_circle()&#039;
But I can&#039;t change references in &#039;app.init&#039; to use &#039;this&#039;, for some reason the JQuery call &#039;$(app.init)&#039; doesn&#039;t set &#039;this&#039; to &#039;app&#039;...  I think that&#039;s where a lot of my confusion started, as I&#039;d change something in &#039;draw_circle&#039; and it would work, then I&#039;d change it in &#039;init&#039; and it wouldn&#039;t!</description>
		<content:encoded><![CDATA[<p>Thanks &#8211; that works!<br />
I&#8217;m still confused around how &#8216;this&#8217; works &#8211; it&#8217;s not really a Coffeescript thing, more of a Javascript thing.<br />
For example, in my code above, I can change references in &#8216;app.draw_circle&#8217; to use &#8216;this&#8217; and they get &#8216;app&#8217;.  Which makes sense, as they are called as &#8216;app.draw_circle()&#8217;<br />
But I can&#8217;t change references in &#8216;app.init&#8217; to use &#8216;this&#8217;, for some reason the JQuery call &#8216;$(app.init)&#8217; doesn&#8217;t set &#8216;this&#8217; to &#8216;app&#8217;&#8230;  I think that&#8217;s where a lot of my confusion started, as I&#8217;d change something in &#8216;draw_circle&#8217; and it would work, then I&#8217;d change it in &#8216;init&#8217; and it wouldn&#8217;t!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jashkenas</title>
		<link>http://www.trouble.net.au/blog/korny/2010/02/25/playing-with-coffeescript/comment-page-1/#comment-31</link>
		<dc:creator>jashkenas</dc:creator>
		<pubDate>Thu, 25 Feb 2010 12:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.trouble.net.au/blog/korny/?p=148#comment-31</guid>
		<description>Nice writeup. It&#039;s very cool to see an example of using Raphael from CoffeeScript.

The problem that you had with &quot;this&quot; is one of my least favorite parts of JavaScript. Unlike everything else in JS (which has proper lexical scope), the value of &quot;this&quot; within a function is the object that the function has been attached to. 

The benefit is that you can pull a function off one object and attach it to another, and it&#039;ll work seamlessly. The downside is that if you pull a function off an object, say, to hand it to a click handler, it loses its notion of identity and it&#039;s former value for &quot;this&quot;.

The common way to address it is to set a local variable to &quot;this&quot; from the outside, and reference it through the closure, instead of &quot;this&quot;. So, your original:

    $(circle.node).click (e) -&gt; this.kick e

Becomes:

    me: this
    $(circle.node).click (e) -&gt; me.kick e

Which will work properly. However, CoffeeScript provides a convenience for defining functions that are bound to the current value of &quot;this&quot;, right on the spot where they&#039;re declared, for use in cases like these.

http://jashkenas.github.com/coffee-script/#fat_arrow

Using the fat arrow, the example becomes:

    $(circle.node).click (e) =&gt; this.kick e

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Nice writeup. It&#8217;s very cool to see an example of using Raphael from CoffeeScript.</p>
<p>The problem that you had with &#8220;this&#8221; is one of my least favorite parts of JavaScript. Unlike everything else in JS (which has proper lexical scope), the value of &#8220;this&#8221; within a function is the object that the function has been attached to. </p>
<p>The benefit is that you can pull a function off one object and attach it to another, and it&#8217;ll work seamlessly. The downside is that if you pull a function off an object, say, to hand it to a click handler, it loses its notion of identity and it&#8217;s former value for &#8220;this&#8221;.</p>
<p>The common way to address it is to set a local variable to &#8220;this&#8221; from the outside, and reference it through the closure, instead of &#8220;this&#8221;. So, your original:</p>
<p>    $(circle.node).click (e) -&gt; this.kick e</p>
<p>Becomes:</p>
<p>    me: this<br />
    $(circle.node).click (e) -&gt; me.kick e</p>
<p>Which will work properly. However, CoffeeScript provides a convenience for defining functions that are bound to the current value of &#8220;this&#8221;, right on the spot where they&#8217;re declared, for use in cases like these.</p>
<p><a href="http://jashkenas.github.com/coffee-script/#fat_arrow" rel="nofollow">http://jashkenas.github.com/coffee-script/#fat_arrow</a></p>
<p>Using the fat arrow, the example becomes:</p>
<p>    $(circle.node).click (e) =&gt; this.kick e</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

