<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://united-coders.com"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>united-coders.com - jQuery</title>
 <link>http://united-coders.com/taxonomy/term/84/0</link>
 <description></description>
 <language>en</language>
<item>
 <title>Handling the unexpected - Type safe functions in Javascript</title>
 <link>http://united-coders.com/matthias-reuter/handling-the-unexpected-type-safe-functions-in-javascript</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Javascript is a weird language. Great but weird. Take functions for example. You cannot only pass any &lt;em&gt;type&lt;/em&gt; of arguments, you can also pass &lt;em&gt;any number&lt;/em&gt; of arguments. This may be quite disturbing, especially for Java developers. Recently I had a discussion with a Java developer who complained about missing code assistance in Javascript, by which he meant no hint about the type of an argument.&lt;/p&gt;
&lt;p&gt;This is of course due to the dynamically typed nature of Javascript. While in Java you denote the expected type of a parameter, and it&#039;s the caller&#039;s duty to pass the correct type (even more, you cannot pass a different type), in Javascript it&#039;s the function&#039;s duty to handle the given parameters and do something reasonable with unexpected types. The question arises: How do you write type safe functions in Javascript? Let me explain this by an example implementation to calculate the greatest common divisor of two numbers.&lt;span class=&quot;read-more&quot;&gt;&lt;a href=&quot;/matthias-reuter/handling-the-unexpected-type-safe-functions-in-javascript&quot;&gt;&lt;strong&gt;Read more&lt;/strong&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;!--
&lt;rdf:RDF xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot; xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:trackback=&quot;http://madskills.com/public/xml/rss/module/trackback/&quot;&gt;
&lt;rdf:Description rdf:about=&quot;http://united-coders.com/matthias-reuter/handling-the-unexpected-type-safe-functions-in-javascript&quot; dc:identifier=&quot;http://united-coders.com/matthias-reuter/handling-the-unexpected-type-safe-functions-in-javascript&quot; dc:title=&quot;Handling the unexpected - Type safe functions in Javascript&quot; trackback:ping=&quot;http://united-coders.com/trackback/34&quot; /&gt;
&lt;/rdf:RDF&gt;
--&gt;
&lt;div class=&#039;sexybookmarks-default-2731&#039;&gt;&lt;/div&gt;</description>
 <comments>http://united-coders.com/matthias-reuter/handling-the-unexpected-type-safe-functions-in-javascript#comments</comments>
 <category domain="http://united-coders.com/category/tags/function">function</category>
 <category domain="http://united-coders.com/category/tags/javascript">javascript</category>
 <category domain="http://united-coders.com/category/tags/jquery">jQuery</category>
 <category domain="http://united-coders.com/category/tags/types">types</category>
 <enclosure url="http://united-coders.com/sites/default/files/jquery.makeTypeSafe.js.txt" length="4662" type="text/plain" />
 <pubDate>Wed, 05 Aug 2009 10:11:59 +0000</pubDate>
 <dc:creator>Matthias Reuter</dc:creator>
 <guid isPermaLink="false">34 at http://united-coders.com</guid>
</item>
</channel>
</rss>


