<?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>David Pratt &#187; function</title> <atom:link href="http://daipratt.co.uk/tag/function/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Thu, 17 May 2012 19:14:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Using a function&#8217;s arguments array in JavaScript</title><link>http://daipratt.co.uk/using-a-functions-arguments-array-in-javascript/</link> <comments>http://daipratt.co.uk/using-a-functions-arguments-array-in-javascript/#comments</comments> <pubDate>Sun, 29 Nov 2009 11:35:48 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[function]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=678</guid> <description><![CDATA[A tutorial that explains how to access a functions arguments array.]]></description> <content:encoded><![CDATA[<p>When you pass parameters into a function, there is an easy way to retrieve them without first pre-defining them.  There is something called the <em>arguments array</em> array which allows you to access the information passed into a function.  Now, because you can determine the size of the arguments array it allows you to do useful things like:</p><pre class="brush: javascript">
function sum() {
  var total = 0;
  for (var i=0; i < arguments.length; i++) {
    total = total + arguments[i];
  }
  return total;
}
sum(5,4,3); //returns 12
</pre><p>What this function does is take any number of parameters and then add them together.</p><p>You can also do the <em>arguments.length</em> technique in reverse by using the length method against the function. This will then give you the number of variables that are expected by a function. For example:</p><pre class="brush: javascript">
function sum(x, y, z){
    return x + y + z;
}
console.log(sum.length); // returns 3, as that is the number of expected parameters.
</pre><p>I can't say I use either of these techniques a great deal, but they are useful to know nonetheless!</p> ]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/using-a-functions-arguments-array-in-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
