<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Phrappe</title>
	<atom:link href="http://phrappe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phrappe.com</link>
	<description>ice-chilled, instant web tips</description>
	<lastBuildDate>Sat, 21 Jan 2017 22:05:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.8.9</generator>
<site xmlns="com-wordpress:feed-additions:1">21636952</site>	<item>
		<title>Repocompare.io</title>
		<link>http://phrappe.com/javascript/repocompare-io/</link>
		<comments>http://phrappe.com/javascript/repocompare-io/#respond</comments>
		<pubDate>Sat, 21 Jan 2017 22:05:01 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[babel]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ES2015]]></category>
		<category><![CDATA[es6]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[jest]]></category>
		<category><![CDATA[JSX]]></category>
		<category><![CDATA[mobx]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[react]]></category>
		<category><![CDATA[reactjs]]></category>
		<category><![CDATA[repositories]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[spa]]></category>
		<category><![CDATA[webpack]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1211</guid>
		<description><![CDATA[Repocompare.io is my latest pet project! With this single page application (SPA) you can quickly and easily search and compare Github repositories. If you need a quick and elegant way to compare projects on how many stars, forks, and issues they have, then just visit Repocompare.io and enjoy! From a technical point of view, this &#8230; <a href="http://phrappe.com/javascript/repocompare-io/" class="more-link">Continue reading <span class="screen-reader-text">Repocompare.io</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://repocompare.io" target="_blank"><strong>Repocompare.io</strong></a> is my latest pet project! With this single page application (SPA) you can quickly and easily search and compare <a href="https://github.com/">Github</a> repositories. If you need a quick and elegant way to compare projects on how many stars, forks, and issues they have, then just visit <a href="http://repocompare.io" target="_blank"><strong>Repocompare.io</strong></a> and enjoy!</p>
<p>From a technical point of view, this project is built on <a href="https://webpack.github.io/">webpack</a> (and <a href="https://babeljs.io/">babel</a>) and is using <strong>ES6</strong> and <strong>JSX</strong> (<strong>ES2015</strong> to be more precise). The project is based on Facebook&#8217;s new beast, <a href="https://facebook.github.io/react/"><strong>React</strong></a>. As a state management, I&#8217;m using <a href="https://mobx.js.org/"><strong>MobX</strong></a>, and many components and tools from React&#8217;s ecosystem, such as <a href="https://github.com/ReactTraining/react-router">React Router</a> and <a href="https://github.com/reactjs/react-autocomplete">React Autocomplete</a>. The test suite/framework is Facebook&#8217;s <a href="https://facebook.github.io/jest/">Jest</a>, which looks and feels really fast. Finally, I used for the very first time <a href="https://github.com/css-modules/css-modules"><strong>CSS modules</strong></a>, a nice implementation of <strong>CSS</strong> that plays nicely with React&#8217;s components.</p>
<p>For those who want to contribute I&#8217;ve already set up a <a href="https://github.com/tsevdos/repocompare/projects/1" target="_blank">project with tasks on Github</a>, so feel free to <a href="https://github.com/tsevdos/repocompare" target="_blank">contribute</a>, especially on the design!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/javascript/repocompare-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1211</post-id>	</item>
		<item>
		<title>My first npm module</title>
		<link>http://phrappe.com/javascript/my-first-npm-module/</link>
		<comments>http://phrappe.com/javascript/my-first-npm-module/#respond</comments>
		<pubDate>Mon, 19 Sep 2016 19:50:30 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[backbone.js]]></category>
		<category><![CDATA[greek]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[spa]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1173</guid>
		<description><![CDATA[Finally, I found the time to update the Greek in Tech site and create my very first npm package! The idea was to extract all the entries from the backbone single page application, create a very simple API for all these data / entries and distribute them as an npm package. That way, I could &#8230; <a href="http://phrappe.com/javascript/my-first-npm-module/" class="more-link">Continue reading <span class="screen-reader-text">My first npm module</span></a>]]></description>
				<content:encoded><![CDATA[<p>Finally, I found the time to update the <a href="http://greekintech.com">Greek in Tech</a> site and create my very first <a href="https://www.npmjs.com/package/greek-in-tech"><strong>npm package</strong></a>! The idea was to extract all the entries from the <a href="https://github.com/tsevdos/greek-in-tech-site">backbone single page application</a>, create a very simple API for all these data / entries and distribute them as an <strong>npm package</strong>. That way, I could easily use it as a <strong>dependency</strong> to the SPA site, with all the benefits of an npm module like reusability, easier maintenance, single responsibility etc.</p>
<p>You can still contribute entries on the <a href="https://github.com/tsevdos/greek-in-tech"><strong>package&#8217;s official repository</strong></a> learn more about it from its <a href="https://www.npmjs.com/package/greek-in-tech"><strong>official npm page</strong></a> (yes the package&#8217;s name is still <a href="https://www.npmjs.com/package/greek-in-tech"><strong>greek-in-tech</strong></a>). Feel free to use it on your own projects and star it if you like it!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/javascript/my-first-npm-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1173</post-id>	</item>
		<item>
		<title>React Boilerplate</title>
		<link>http://phrappe.com/javascript/react-boilerplate/</link>
		<comments>http://phrappe.com/javascript/react-boilerplate/#respond</comments>
		<pubDate>Wed, 27 Jul 2016 13:24:27 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[es6]]></category>
		<category><![CDATA[eslint]]></category>
		<category><![CDATA[reactjs]]></category>
		<category><![CDATA[webpack]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1153</guid>
		<description><![CDATA[Hi all, after the very successful Gulp boilerplate for web designers and Grunt boilerplate for web designers, I’m very pleased to announce my React boilerplate (it’s as designers friendly as it can be). It comes with ES6 and ESlint out of the box, and with a webpack configuration that you can actually understand and built &#8230; <a href="http://phrappe.com/javascript/react-boilerplate/" class="more-link">Continue reading <span class="screen-reader-text">React Boilerplate</span></a>]]></description>
				<content:encoded><![CDATA[<p>Hi all, after the very successful <a href="http://phrappe.com/javascript/gulp-boilerplate-for-web-designers/">Gulp boilerplate for web designers</a> and <a href="http://phrappe.com/javascript/grunt-boilerplate-for-web-designers/">Grunt boilerplate for web designers</a>, I’m very pleased to announce my <strong><a href="https://github.com/tsevdos/react-boilerplate" target="_blank">React boilerplate</a></strong> (it’s as designers friendly as it can be).</p>
<p>It comes with <strong>ES6</strong> and <strong>ESlint</strong> out of the box, and with a <strong>webpack</strong> configuration that you can actually understand and built on top of it. Feel free to fork, download and play with it!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/javascript/react-boilerplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1153</post-id>	</item>
		<item>
		<title>Extending Class methods with Module Mixins</title>
		<link>http://phrappe.com/ruby/extending-class-methods-with-module-mixins/</link>
		<comments>http://phrappe.com/ruby/extending-class-methods-with-module-mixins/#respond</comments>
		<pubDate>Mon, 01 Feb 2016 19:04:56 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1089</guid>
		<description><![CDATA[I&#8217;m about to finish the Eloquent Ruby book (excellent book by the way) and keep finding ruby pearls of wisdom. One of these is that you can actually use module mixins to extend class methods! You only need to declare a module mixin as normal, and then include it on the singleton class of your &#8230; <a href="http://phrappe.com/ruby/extending-class-methods-with-module-mixins/" class="more-link">Continue reading <span class="screen-reader-text">Extending Class methods with Module Mixins</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m about to finish the <a href="http://www.amazon.com/gp/product/0321584104/">Eloquent Ruby book</a> (excellent book by the way) and keep finding ruby pearls of wisdom. One of these is that you can actually use <strong>module mixins</strong> to extend <strong>class methods</strong>! You only need to declare a module mixin as normal, and then include it on the <strong>singleton class</strong> of your declared class (&#8220;Klass&#8221; in our example).</p>
<p><script src="https://gist.github.com/tsevdos/7d5f4e2c9b592cb7d0d2.js?file=example.rb"></script></p>
<p>Then we can use it just like any other <strong>class method</strong>. </p>
<p><script src="https://gist.github.com/tsevdos/7d5f4e2c9b592cb7d0d2.js?file=usage.rb"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/ruby/extending-class-methods-with-module-mixins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1089</post-id>	</item>
		<item>
		<title>Greek in Tech</title>
		<link>http://phrappe.com/javascript/greek-in-tech/</link>
		<comments>http://phrappe.com/javascript/greek-in-tech/#respond</comments>
		<pubDate>Mon, 14 Dec 2015 08:07:04 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[backbone.js]]></category>
		<category><![CDATA[require.js]]></category>
		<category><![CDATA[spa]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1076</guid>
		<description><![CDATA[Greek in Tech is my latest side project and is finally live! As you can see, it&#8217;s a very simple single-page application (SPA) that displays greek words we use in technology. Github pages is hosting/serving everything, and the application is based on Backbonejs framework and Requirejs module loader. Feel free to contribute and spread the &#8230; <a href="http://phrappe.com/javascript/greek-in-tech/" class="more-link">Continue reading <span class="screen-reader-text">Greek in Tech</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong><a href="http://greekintech.com/">Greek in Tech</a></strong> is my latest side project and is finally live! As you can see, it&#8217;s a very simple <strong>single-page application</strong> (<strong>SPA</strong>) that displays greek words we use in technology. <a href="https://pages.github.com/">Github pages</a> is hosting/serving everything, and the application is based on <a href="http://backbonejs.org/">Backbonejs</a> framework and <a href="http://requirejs.org/">Requirejs</a> module loader. Feel free to contribute and spread the word!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/javascript/greek-in-tech/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1076</post-id>	</item>
		<item>
		<title>Ruby Hash iteration with index</title>
		<link>http://phrappe.com/ruby/ruby-hash-iteration-with-index/</link>
		<comments>http://phrappe.com/ruby/ruby-hash-iteration-with-index/#respond</comments>
		<pubDate>Sat, 12 Dec 2015 09:40:10 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[enumerable]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1069</guid>
		<description><![CDATA[Ruby Hash (and Array) includes the Enumerable module (mixin), which provides a lot of neat, but also slightly hidden in the documentation, methods. This means that despite the poor advertising you can iterate not only each key and value, but the index as well:]]></description>
				<content:encoded><![CDATA[<p><a href="http://ruby-doc.org/core-2.2.3/Hash.html" target="_blank">Ruby Hash</a> (and <a href="http://ruby-doc.org/core-2.2.3/Array.html">Array</a>) includes the <a href="http://ruby-doc.org/core-2.2.3/Enumerable.html" target="_blank">Enumerable module (mixin)</a>, which provides a lot of neat, but also slightly hidden in the documentation, methods. This means that despite the poor advertising you can iterate not only each key and value, but the index as well:</p>
<p><script src="https://gist.github.com/tsevdos/7ea0074a5933aa9866e7.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/ruby/ruby-hash-iteration-with-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1069</post-id>	</item>
		<item>
		<title>Ruby tips</title>
		<link>http://phrappe.com/ruby/ruby-tips/</link>
		<comments>http://phrappe.com/ruby/ruby-tips/#respond</comments>
		<pubDate>Mon, 14 Sep 2015 08:00:29 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[block_given?]]></category>
		<category><![CDATA[case statement]]></category>
		<category><![CDATA[here docs]]></category>
		<category><![CDATA[here documents]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[object instance]]></category>
		<category><![CDATA[ranges]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[variables]]></category>
		<category><![CDATA[yields]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1043</guid>
		<description><![CDATA[I just read the Ruby Pocket Reference, a great intro for the Ruby language and want to share a few helpful Ruby tips learned. Parallel assignment of variables In Ruby, you can assign several values to several variables in a single expression (aka. one-liner). The values can be of any type, making it even better! &#8230; <a href="http://phrappe.com/ruby/ruby-tips/" class="more-link">Continue reading <span class="screen-reader-text">Ruby tips</span></a>]]></description>
				<content:encoded><![CDATA[<p>I just read the <a href="http://www.amazon.com/Ruby-Pocket-Reference-OReilly/dp/0596514816/ref=sr_1_2?s=books&#038;ie=UTF8&#038;qid=1439116366&#038;sr=1-2&#038;keywords=Ruby+Pocket+Reference">Ruby Pocket Reference</a>, a great intro for the <a href="https://www.ruby-lang.org/">Ruby language</a> and want to share a few helpful Ruby tips learned.</p>
<h2>Parallel assignment of variables</h2>
<p>In Ruby, you can assign several values to several variables in a single expression (aka. one-liner). The values can be of any type, making it even better! The result is pretty impressive, check out the snippet below :</p>
<p><script src="https://gist.github.com/tsevdos/5156671a5240929bfa4e.js?file=example_1.rb"></script></p>
<p>You can even return multiple values from methods!</p>
<p><script src="https://gist.github.com/tsevdos/5156671a5240929bfa4e.js?file=example_2.rb"></script></p>
<p>And in case the above example didn&#8217;t quite impress you, see how convenient it can be on a real-world example :</p>
<p><script src="https://gist.github.com/tsevdos/5156671a5240929bfa4e.js?file=example_3.rb"></script></p>
<h2>Here Documents</h2>
<p>You can build multiple line strings using here documents. Ruby supports both single and double-quoted strings on here documents, have a look at the examples :</p>
<p><script src="https://gist.github.com/tsevdos/05580fce12c1cd6fe118.js"></script></p>
<h2>Ranges</h2>
<p>Ruby supports ranges of numbers which can be very handy. You can define a range of numbers using the starting value followed by <code>..</code> (2 dots)  or <code>...</code> (3 dots) and the end value. On the first case the range includes the last value, and on the other one excludes it. For example :</p>
<p><script src="https://gist.github.com/tsevdos/fa82d7afa1960a0b2f6c.js?file=ranges.rb"></script></p>
<p>Ranges can be used in many cases such as :</p>
<p><strong>Loops</strong></p>
<p><script src="https://gist.github.com/tsevdos/fa82d7afa1960a0b2f6c.js?file=loops_with_ranges.rb"></script></p>
<p><strong>Comparison</strong></p>
<p><script src="https://gist.github.com/tsevdos/fa82d7afa1960a0b2f6c.js?file=comparison_and_ranges.rb"></script></p>
<p><strong>and creating arrays</strong></p>
<p><script src="https://gist.github.com/tsevdos/fa82d7afa1960a0b2f6c.js?file=create_arrays_using_ranges.rb"></script></p>
<h2>Default arguments</h2>
<p>Another great feature!</p>
<p><script src="https://gist.github.com/tsevdos/14240c011289ce9d2e48.js"></script></p>
<h2><code>block_given?</code> on <code>yields</code></h2>
<p>A <code>yield</code> statement executes a code block associated with a method. You probably know that already (if not have a look at the examples below), what you probably don&#8217;t know is the <code>block_given?</code> method that checks if a code block is passed to the method.</p>
<p><script src="https://gist.github.com/tsevdos/785589e80ca881c642d5.js"></script></p>
<h2>Case statement tricks</h2>
<p>Case staments in Ruby are very flexible. They come in two main flavors, multiline for writing many statements and one-liners, that looks much better:</p>
<p><script src="https://gist.github.com/tsevdos/1406c59721ba5000400e.js?file=multiline_and_oneline_examples.rb"></script></p>
<p>You can also assign a value using the case statement in Ruby:</p>
<p><script src="https://gist.github.com/tsevdos/1406c59721ba5000400e.js?file=assign_value.rb"></script></p>
<h2>Usefull object instance methods</h2>
<p>As a final tip, I enlist the most useful public methods of the Object class (the base class for Ruby, all other types inherit these methods). All of them are helpful, but I tend to use the debugging-oriented ones the most :</p>
<ul>
<li><code>obj.inspect</code></li>
<li><code>obj.class</code></li>
<li><code>obj.ancestors</code></li>
<li><code>obj.instance_variables</code></li>
<li><code>obj.methods</code> (also <code>obj.private_methods</code>, <code>obj.protected_methods</code> and <code>obj.public_methods</code> can be handy as well)</li>
<li><code>obj.to_s</code> (sometimes <code>obj.to_a</code> can be handy as well)</li>
</ul>
<p>Not bad for an introductory Ruby book. If you like the post stay tuned for more!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/ruby/ruby-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1043</post-id>	</item>
		<item>
		<title>Avoid CoffeeScript &#038; use ES6!</title>
		<link>http://phrappe.com/javascript/avoid-coffeescript-and-use-es6/</link>
		<comments>http://phrappe.com/javascript/avoid-coffeescript-and-use-es6/#comments</comments>
		<pubDate>Mon, 03 Aug 2015 21:14:11 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[es6]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=1025</guid>
		<description><![CDATA[Those of you that follow my blog might have noticed how fond I am to some of CoffeeScript&#8217;s conveniences. They are excellent, but it&#8217;s time to leave them behind and start using ES6. Most of CoffeeScript&#8217;s goodies already exist in ES6 (with some syntax changes), and your code is guaranteed to be future proof. And &#8230; <a href="http://phrappe.com/javascript/avoid-coffeescript-and-use-es6/" class="more-link">Continue reading <span class="screen-reader-text">Avoid CoffeeScript &#038; use ES6!</span></a>]]></description>
				<content:encoded><![CDATA[<p>Those of you that follow my blog might have noticed how fond I am to some of CoffeeScript&#8217;s conveniences. They are excellent, but it&#8217;s time to leave them behind and start using <a href="http://es6-features.org/">ES6</a>. Most of <a href="https://robots.thoughtbot.com/replace-coffeescript-with-es6">CoffeeScript&#8217;s goodies already exist in ES6 (with some syntax changes)</a>, and your code is guaranteed to be future proof. And if time spent learning CoffeeScript feels like a waste, there&#8217;s good news &#8211; with a solid CoffeeScript base, transitioning to ES6 will be a piece of cake!</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/javascript/avoid-coffeescript-and-use-es6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">1025</post-id>	</item>
		<item>
		<title>Coffeescript gotchas (part 4): Scope and Objects</title>
		<link>http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/</link>
		<comments>http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/#comments</comments>
		<pubDate>Sat, 06 Jun 2015 07:47:28 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[super]]></category>
		<category><![CDATA[this]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=994</guid>
		<description><![CDATA[This is the fourth and final part of the CoffeeScript gotchas series. On this part I&#8217;ll demonstrate Coffeescript&#8217;s syntactic sugar on Objects, constructors and classes! Ready, set, go&#8230; Update: Table of contents CoffeeScript gotchas (part 1): Comments, strings, booleans, arrays and functions Coffeescript gotchas (part 2): Operators and aliases Coffeescript gotchas (part 3): Switch statement &#8230; <a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/" class="more-link">Continue reading <span class="screen-reader-text">Coffeescript gotchas (part 4): Scope and Objects</span></a>]]></description>
				<content:encoded><![CDATA[<p>This is the fourth and final part of the CoffeeScript gotchas series. On this part I&#8217;ll demonstrate Coffeescript&#8217;s syntactic sugar on Objects, constructors and classes! Ready, set, go&#8230;</p>
<h5>Update: Table of contents</h5>
<nav class="table-of-contents">
<ol>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-1-comments-strings-booleans-arrays-and-functions/">CoffeeScript gotchas (part 1): Comments, strings, booleans, arrays and functions</a></li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-2-operators-and-aliases/">Coffeescript gotchas (part 2): Operators and aliases</a></li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/">Coffeescript gotchas (part 3): Switch statement and loops</a>
</li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/">Coffeescript gotchas (part 4): Scope and Objects</a></li>
</ol>
</nav>
<h2>Classes</h2>
<p>Probably the most valuable feature that CoffeeScript syntax offers at the moment. With the <code>class</code> keyword you can create a new class (CoffeeScript is using the constructor function under the hood) and with the <code>extend</code> keyword you can extend one. To make things even easier, CoffeeScript provides an <code>initialization</code> (aka <code>constructor</code>) function, in case you need it. Just use the <code>contstructor</code> method and you are ready to go. You can use the concept of <code>super</code> method which represents a reference to the superclass version of the method you&#8217;re in (very Ruby-like). I&#8217;m sure that all these will make more sense with the following example&#8230;</p>
<div data-height="268" data-theme-id="0" data-slug-hash="mJeJWR" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>class Animal
  constructor: (@name) -&gt;
  move: (meters) -&gt;
    console.log &quot;#{@name} moved #{meters} meters.&quot;

class Snake extends Animal
  move: -&gt;
    console.log &quot;Slithering...&quot;
    super 5

class Horse extends Animal
  move: -&gt;
    console.log &quot;Galloping...&quot;
    super 45

sam = new Snake &quot;Sammy the Python&quot;
tom = new Horse &quot;Tommy the Palomino&quot;

sam.move()
tom.move()</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/mJeJWR/'>Coffeescript gotchas (part 4): Classes</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<h2>Constructors</h2>
<p>You can set up instance variables with the classic <code>this</code> Javascript keyword (CoffeeScript translates to Javascript after all), but you can save a couple of characters and maybe lines, by using the <code>@</code> symbol. You can also save a couple of more lines by omitting the instance name.</p>
<div data-height="268" data-theme-id="0" data-slug-hash="KpdqLV" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>class Animal
  constructor: (name, height, weight) -&gt;
    @name = name
    @height = height
    @weight = weight

# same as above
class Animal
  constructor: (@name, @height, @weight) -&gt;</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/KpdqLV/'>Coffeescript gotchas (part 4): Constructors</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<h2>Scope</h2>
<p>Finally, if you want to pass an instance method as a callback, use the <code>=></code>, also known as &#8220;fat arrow&#8221;. The &#8220;fat arrow&#8221; binds the object&#8217;s instance to <code>this</code> and makes your code easier to read. This will also be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions" title="ES6 fat arrow">ES6 feature</a>, so it makes a lot of sense to get used to it.</p>
<div data-height="268" data-theme-id="0" data-slug-hash="MwaoMb" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>class Message
  constructor: (@txt) -&gt;
  thin: -&gt; console.log @txt
  fat:  =&gt; console.log @txt

msg = new Message &quot;yo&quot;
msg.thin() # works
msg.fat()  # works

fn = (callback) -&gt; callback()

fn(msg.thin) # =&gt; &quot;undefined&quot;
fn(msg.fat)  # works
fn(-&gt; msg.thin()) # works</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/MwaoMb/'>Coffeescript gotchas (part 4): Scope</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<p>This has been the final part of the series &#8211; see you around and stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">994</post-id>	</item>
		<item>
		<title>Coffeescript gotchas (part 3): Switch statement and loops</title>
		<link>http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/</link>
		<comments>http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/#comments</comments>
		<pubDate>Sat, 23 May 2015 08:34:43 +0000</pubDate>
		<dc:creator><![CDATA[John Tsevdos]]></dc:creator>
				<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://phrappe.com/?p=985</guid>
		<description><![CDATA[Welcome to the third part of Coffeescript gotchas. If you haven&#8217;t yet read the first and second part of the series I strongly recommend to have a look. The main topic today is loops plus the switch statement. CoffeeScript offers a lot of enchantments and syntactic sugar to them. Update: Table of contents CoffeeScript gotchas &#8230; <a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/" class="more-link">Continue reading <span class="screen-reader-text">Coffeescript gotchas (part 3): Switch statement and loops</span></a>]]></description>
				<content:encoded><![CDATA[<p>Welcome to the third part of Coffeescript gotchas. If you haven&#8217;t yet read the <a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-1-comments-strings-booleans-arrays-and-functions/">first</a> and <a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-2-operators-and-aliases/">second</a> part of the series I strongly recommend to have a look. The main topic today is loops plus the switch statement. CoffeeScript offers a lot of enchantments and syntactic sugar to them.</p>
<h5>Update: Table of contents</h5>
<nav class="table-of-contents">
<ol>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-1-comments-strings-booleans-arrays-and-functions/">CoffeeScript gotchas (part 1): Comments, strings, booleans, arrays and functions</a></li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-2-operators-and-aliases/">Coffeescript gotchas (part 2): Operators and aliases</a></li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/">Coffeescript gotchas (part 3): Switch statement and loops</a>
</li>
<li><a href="http://phrappe.com/coffeescript/coffeescript-gotchas-part-4-scope-and-objects/">Coffeescript gotchas (part 4): Scope and Objects</a></li>
</ol>
</nav>
<h2>Switch statement</h2>
<p>At last, an easier way to write switch statements. If your switch case contains a single line of code, you can write the entire thing in a single line using the <code>then</code> keyword (see second example).</p>
<div data-height="268" data-theme-id="0" data-slug-hash="zGvxQy" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>name = &quot;John&quot;

# normal switch statement
switch name
  when &quot;John&quot;
    console.log &quot;This guy rocks!&quot;
  when &quot;Jon&quot;
    console.log &quot;Still cool guy&quot;
  else
    console.log &quot;Good lad.&quot;
    
# switch statement using the then keyword
switch name
  when &quot;John&quot; then console.log &quot;This guy rocks!&quot;
  when &quot;Jon&quot; then console.log &quot;Still cool guy&quot;
  else console.log &quot;Good lad.&quot;</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/zGvxQy/'>Coffeescript gotchas (part 3): switch statement and loops</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<h2>For Loops</h2>
<p>For loops have many flavors and great potential in CoffeeScript. You can loop through arrays and objects and still keep your code clean and hassle-free. Just take a deep breath and try to absorb as many flavours as you can. They can all come very handy.</p>
<h3>Arrays</h3>
<p>Iterating Arrays have never been easier&#8230;</p>
<div data-height="268" data-theme-id="0" data-slug-hash="NPemew" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>arr = [&quot;Ned Stark&quot;, &quot;Jon Snow&quot;, &quot;Arya Stark&quot;, &quot;Jaime Lannister&quot;]

# basic array iteration
for name in arr
    console.log name

# array iteration (with index)
for name , i in arr
    console.log &quot;#{i}: #{name}&quot;

# array filtering (with index)
for name, i in arr when name.indexOf &quot;J&quot; is 0
    console.log &quot;#{i}: #{name}&quot;

# array iteration for every second item
for name , i in arr by 2
    console.log &quot;#{i}: #{name}&quot;</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/NPemew/'>Coffeescript gotchas (part 3): switch statement and loops</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<h3>Objects</h3>
<p>Looping through an object&#8217;s key/value pairs is also very easy. You can also loop through just the direct key/value pairs (not the inherited ones) by using the <code>own</code> keyword (which will use the <code>hasOwnProperty</code> method under the hood).</p>
<div data-height="268" data-theme-id="0" data-slug-hash="dPwLao" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code>ned =
  name : &quot;Ned Stark&quot;
  house : &quot;Stark&quot;
  words : &quot;Winter is coming&quot;

# print all properties of an object
for key, value of ned 
  console.log &quot;#{key} : #{value}&quot;

# print all own properties of an object
for own key, value of ned
  console.log &quot;#{key} : #{value}&quot;</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/dPwLao/'>Coffeescript gotchas (part 3): switch statement and loops</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<h3>While Loops</h3>
<p>The <code>while</code> loop has 3 syntax flavors to make your code more descriptive and your life easier. Try to use <code>unless</code> instead of <code>while not</code>, as it&#8217;s easier and preferable.</p>
<div data-height="268" data-theme-id="0" data-slug-hash="gbZyEm" data-default-tab="js" data-user="tsevdos" class='codepen'>
<pre><code># Normal while
num = 10
while num
  console.log num
  num--

# while not
num = 10
while not (num is 0)
  console.log num
  num--

# exactly the same as the above example
num = 10
until num is 0
  console.log num
  num--</code></pre>
<p>See the Pen <a href='http://codepen.io/tsevdos/pen/gbZyEm/'>Coffeescript gotchas (part 3): switch statement and loops</a> by John Tsevdos (<a href='http://codepen.io/tsevdos'>@tsevdos</a>) on <a href='http://codepen.io'>CodePen</a>.</p>
</div>
<p><script async src="//assets.codepen.io/assets/embed/ei.js"></script></p>
<p>As you can see CoffeeScript is very handy when it comes to loops. Keep in mind and stay tuned for the fourth and final part of the <strong>Coffeescript gotchas</strong> series where we&#8217;ll have a look at the syntactic sugar that CoffeeScript provides on Scope and Objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://phrappe.com/coffeescript/coffeescript-gotchas-part-3-switch-statement-and-loops/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">985</post-id>	</item>
	</channel>
</rss>
