﻿ Numeric literals ﻿

Main Page

# Numeric literals

Here, the function named
sum()
takes two parameters of type
Integer
and returns an
Integer
(as
indicated by the semicolon after the closing parenthesis). If the function doesn’t return a value, it is
defined as type
Void
:
function doNothing(num1 : Integer, num2 : Integer) : Void {
num1 + num2;
}
Functions that have argument and return value types defined are type checked, although it is possible to
leave off the types and have functions behave as they do in ECMAScript today.
Java: Just define as many functions as necessary with different argument lists. For example, you could
make two different versions of the
sum()
function defined earlier, one to take two arguments and one to
take three:
function sum(num1 : Integer, num2 : Integer) : Integer {
return num1 + num2;
}
function sum(num1 : Integer, num2 : Integer, num3 : Integer) : Integer {
return num1 + num2 + num3;
}
Another change to functions is the capability to define named arguments, which are optional and can be
assigned in any order so long as the name of the argument is used. For example, the following function
contains two named arguments:
function sum(num1 : Integer, num2: Integer, named num3 : Integer = 7, named num4 :
Integer = 10) {
return num1 + num2 + num3 + num4;
}
To call this function, you can use only two arguments, three arguments, or all four:
result = sum(10, 20);
result = sum(10, 20, num3: 10);
result = sum(10, 20, num4: 10, num3: 20);
Note the last two lines where the named arguments are used; specifically notice the last line, where
num4
is used before
num3
.
Numeric literals
In order to support more types of numbers, the Netscape proposal introduces three new types of num-
bers: long, unsigned long (ulong), and float. You can indicate the type of number by including an
l
(or
L
)
for long values,
ul
(or
uL
,
Ul
,
UL
) for ulong values, and
f
(or
F
) for float values. For example,
L25
is a
long,
UL25
is a ulong, and
F25
is a float.
600
Chapter 20
23_579088 ch20.qxd 3/28/05 11:44 AM Page 600

Free JavaScript Editor     Ajax Editor