JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
functions with optional args? Posted by tamzynb on 25 Sept 2001 at 7:49 AM
hi,

does anyone know who to implement a optional argument in javascript. If it's possible that is...

i.e

function cloths(socks,shoes,optional pants){
puton=true
...
}

From all searching all I can't find a yes or no, though when I try it like above I get an error.

cheers Tamzyn

Report
Re: functions with optional args? Posted by Darius on 2 Oct 2001 at 3:25 PM
: hi,
:
: does anyone know who to implement a optional argument in javascript. If it's possible that is...
:
: i.e
:
: function cloths(socks,shoes,optional pants){
: puton=true
: ...
: }
:
: From all searching all I can't find a yes or no, though when I try it like above I get an error.
:
: cheers Tamzyn
:
In JavaScript all parameters are optional, there is no special syntax for it. I don't think there is a syntax for specifying default parameters.

Here's an example...

function test(x){
alert(x);
}

test(5);
test();

Why did you think putting optional in would work? or what language did you come from to get that?


"No Bad Religion song can make your life complete."
-No Direction, Bad Religion





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.