Optional param in a javascript fct

J

JellyON

Hello everybody. I'm trying to use an optional parameters in a
javascript function and don't succeed.

If I believe in the page at <http://www.mozilla.org/js/language/js20-
2002-
04/core/functions.html#N-Parameter>, it's possible at least in
Javascript 2.0 (don't know for the others versions).

Here is what I do :

<script language="JavaScript"><!--
function Test(a,b=100){alert("a=" & a & ", b=" & b);}
//--></script>

And, too, with <script language="JavaScript2.0">.

And it doesn't work. The javascript console binded with Mozilla indicate
the "=" as being an error, telling it wait a ")" after the formal
parameters

I've tried differents syntax too, without success(example : function
Test(a,b:Integer=100)).

How to proceed ? And, do these optional params specific to javascript
2.0 ?
 
M

Michael Winter

I'm trying to use an optional parameters in a javascript function and
don't succeed.

Optional arguments are not implemented in current browsers. However, you
can produce the same effect yourself:

function Test(a, b) {
if('undefined' == typeof b) {b = 100;}

/* ... */
}

[snip]

Mike
 
V

VK

Here is what I do :
<script language="JavaScript"><!--
function Test(a,b=100){alert("a=" & a & ", b=" & b);}
//--></script>

What mf did learn you to do such things any way? Even Bezerkly system
doesn't imply it. What school are you from? Street mf's society?
 
J

JellyON

What mf did learn you to do such things any way? Even Bezerkly system
doesn't imply it. What school are you from? Street mf's society?

Simply not used to use javascript, but open minded, anyway ;-)
 
J

JellyON

I'm trying to use an optional parameters in a javascript function and
don't succeed.

Optional arguments are not implemented in current browsers. However, you
can produce the same effect yourself:

function Test(a, b) {
if('undefined' == typeof b) {b = 100;}

/* ... */
}

[snip]

Mike

Nice, i'll go this way. Thanks a lot Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top