<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Default Arguments in JavaScript Functions</title>
	<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/</link>
	<description>The building blocks of a solid frontend.</description>
	<pubDate>Fri, 12 Mar 2010 04:24:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Hammad</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-23170</link>
		<author>Hammad</author>
		<pubDate>Thu, 01 Oct 2009 11:29:25 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-23170</guid>
		<description>Hello, to the last message of Rohan, there can be several ways to accomplish this, ofcourse you can put any number of if and switch statements but I liked the solution author has gave, its neat and clean. Guess what I am accepting 6 variables and that would have get me to put 6 if else statements. Good work fatbrain!</description>
		<content:encoded><![CDATA[<p>Hello, to the last message of Rohan, there can be several ways to accomplish this, ofcourse you can put any number of if and switch statements but I liked the solution author has gave, its neat and clean. Guess what I am accepting 6 variables and that would have get me to put 6 if else statements. Good work fatbrain!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: firefight</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-22789</link>
		<author>firefight</author>
		<pubDate>Fri, 18 Sep 2009 14:31:47 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-22789</guid>
		<description>Although your solution is no doubt "cool", I can't see your rational at all. You said the original solution is not sufficient but you gave no reason why, and I don't see any advantage of your proposed solution over it. You basically replaced a simple one line IF statement that is commonly understood practice throughout the industry (aka a common idiom) with a monster. You would definitely need more justification to do something like this in a production system where there is more than one developer working on it.</description>
		<content:encoded><![CDATA[<p>Although your solution is no doubt &#8220;cool&#8221;, I can&#8217;t see your rational at all. You said the original solution is not sufficient but you gave no reason why, and I don&#8217;t see any advantage of your proposed solution over it. You basically replaced a simple one line IF statement that is commonly understood practice throughout the industry (aka a common idiom) with a monster. You would definitely need more justification to do something like this in a production system where there is more than one developer working on it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lionheart</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-20229</link>
		<author>lionheart</author>
		<pubDate>Fri, 26 Jun 2009 18:29:00 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-20229</guid>
		<description>Maybe I'm crazy, and I only read 75% of the comments, but how do you supply a default value for say... ONLY the fifth parameter of a function?

This is the only way I see how:
var asdf = function(a, b, c, d, e).defaults(undefined,undefined,undefined,undefined,'mydefaultvalue');

And given how often the later parameters are optional and first ones are required, I'd much rather use your original, inituitive  typeof solution which requires no extra code to hunt down or include.</description>
		<content:encoded><![CDATA[<p>Maybe I&#8217;m crazy, and I only read 75% of the comments, but how do you supply a default value for say&#8230; ONLY the fifth parameter of a function?</p>
<p>This is the only way I see how:<br />
var asdf = function(a, b, c, d, e).defaults(undefined,undefined,undefined,undefined,&#8217;mydefaultvalue&#8217;);</p>
<p>And given how often the later parameters are optional and first ones are required, I&#8217;d much rather use your original, inituitive  typeof solution which requires no extra code to hunt down or include.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dihymo</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-18891</link>
		<author>Dihymo</author>
		<pubDate>Sun, 17 May 2009 21:21:21 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-18891</guid>
		<description>Default argument values allow to modify functions when modifying mountains of code is silly.

Also default behavior in many cases means only rarely does an extra argument get added.

Why is it so mysterious?</description>
		<content:encoded><![CDATA[<p>Default argument values allow to modify functions when modifying mountains of code is silly.</p>
<p>Also default behavior in many cases means only rarely does an extra argument get added.</p>
<p>Why is it so mysterious?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shaili</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-16650</link>
		<author>shaili</author>
		<pubDate>Wed, 18 Mar 2009 12:44:05 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-16650</guid>
		<description>hi there..

I am developing a .bat file that required javascript file to run. this javascript uses parameter passed to it by .bat file which invokes it.could anyone tell me how to access this parameter in javascript function ??

thanks in advance</description>
		<content:encoded><![CDATA[<p>hi there..</p>
<p>I am developing a .bat file that required javascript file to run. this javascript uses parameter passed to it by .bat file which invokes it.could anyone tell me how to access this parameter in javascript function ??</p>
<p>thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rev</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14941</link>
		<author>rev</author>
		<pubDate>Tue, 02 Dec 2008 19:23:51 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14941</guid>
		<description>/raises a glass

thanks fatbrain</description>
		<content:encoded><![CDATA[<p>/raises a glass</p>
<p>thanks fatbrain</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LOL</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14771</link>
		<author>LOL</author>
		<pubDate>Mon, 03 Nov 2008 11:05:03 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14771</guid>
		<description>LOL, instead of keeping it simple:
  a = typeof(a) != 'undefined' ? a : 42;
  b = typeof(b) != 'undefined' ? b : 'default_b';

You decided that create a new function and having to use a new way to declare function, a better idea?

So if I have 1 value I want to default to something, instead of adding one line of code, I have to add 10?

HAHAHA</description>
		<content:encoded><![CDATA[<p>LOL, instead of keeping it simple:<br />
  a = typeof(a) != &#8216;undefined&#8217; ? a : 42;<br />
  b = typeof(b) != &#8216;undefined&#8217; ? b : &#8216;default_b&#8217;;</p>
<p>You decided that create a new function and having to use a new way to declare function, a better idea?</p>
<p>So if I have 1 value I want to default to something, instead of adding one line of code, I have to add 10?</p>
<p>HAHAHA</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: drawrof</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14408</link>
		<author>drawrof</author>
		<pubDate>Mon, 06 Oct 2008 20:27:05 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-14408</guid>
		<description>"...if you pass that function zero or false or anything else JS evaluates as false, it sticks in the default value, even if what you really wanted to pass was zero, false, etc. Bad news..."

What about using the "is not exactly equal to" operator, that way you can still pass it false or 0 or something.

a = typeof(a) !== 'undefined' ? a : 42;</description>
		<content:encoded><![CDATA[<p>&#8220;&#8230;if you pass that function zero or false or anything else JS evaluates as false, it sticks in the default value, even if what you really wanted to pass was zero, false, etc. Bad news&#8230;&#8221;</p>
<p>What about using the &#8220;is not exactly equal to&#8221; operator, that way you can still pass it false or 0 or something.</p>
<p>a = typeof(a) !== &#8216;undefined&#8217; ? a : 42;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohan</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-13116</link>
		<author>Rohan</author>
		<pubDate>Wed, 06 Aug 2008 08:39:07 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-13116</guid>
		<description>There is an easier way:

function my_func(arg1)
{
   if(!arg1){
   var arg1='default_argument_value';
   }
}</description>
		<content:encoded><![CDATA[<p>There is an easier way:</p>
<p>function my_func(arg1)<br />
{<br />
   if(!arg1){<br />
   var arg1=&#8217;default_argument_value&#8217;;<br />
   }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fatbrain</title>
		<link>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-5916</link>
		<author>fatbrain</author>
		<pubDate>Thu, 25 Oct 2007 16:58:01 +0000</pubDate>
		<guid>http://parentnode.org/javascript/default-arguments-in-javascript-functions/#comment-5916</guid>
		<description>Thanks for input e-voc. What if we consider:

Function.prototype.defaults = function()
{
  var _f = this;
  var _a = Array(_f.length-arguments.length).concat(
    Array.prototype.slice.apply(arguments));
  return function()
  {
    return _f.apply(this, Array.prototype.slice.apply(arguments).concat(
      _a.slice(arguments.length, _a.length)));
  }
}

Or did I get it wrong? Anyhow, give it a testspin and get back to me.

Damn I'm hungry, need food for brain. (I only change the "this" argument in the apply on the inner function)

Cheers // fatbrain</description>
		<content:encoded><![CDATA[<p>Thanks for input e-voc. What if we consider:</p>
<p>Function.prototype.defaults = function()<br />
{<br />
  var _f = this;<br />
  var _a = Array(_f.length-arguments.length).concat(<br />
    Array.prototype.slice.apply(arguments));<br />
  return function()<br />
  {<br />
    return _f.apply(this, Array.prototype.slice.apply(arguments).concat(<br />
      _a.slice(arguments.length, _a.length)));<br />
  }<br />
}</p>
<p>Or did I get it wrong? Anyhow, give it a testspin and get back to me.</p>
<p>Damn I&#8217;m hungry, need food for brain. (I only change the &#8220;this&#8221; argument in the apply on the inner function)</p>
<p>Cheers // fatbrain</p>
]]></content:encoded>
	</item>
</channel>
</rss>
