Main Page

Types

Types
Netscape’s proposal introduces several new types:
?
Never
— Has no values
?
Void
— Replaces the Undefined type from ECMAScript Edition 3
?
Integer
— All integer values
?
char
— All single 16-bit Unicode characters
?
Type
— The supertype of all types
Unlike ECMAScript Edition 3, all types are considered objects and not primitive values.
New
machine types
represent primitive number values:
?
sbyte
— Signed byte integer, values between –128 and 127
?
byte
— Byte integer, values between 0 and 255
?
short
— Short integer, values between –32768 and 32767
?
ushort
— Unsigned short integer, values between 0 and 65535
?
int
— Integer, values between –2147483648 and 2147483647
?
uint
— Unsigned integer, values between 0 and 4294967295
?
long
— Long integer, values between –9223372036854775808 and 9223372036854775807
?
ulong
– Unsigned long integer, values between 0 and 18446744073709551615
?
float
— Floating-point number, all single precision IEEE floating-point numbers
The machine types can be used in place of regular types whenever a number must be represented. For
example:
var b : byte = 10;
var longnum : long = L100;
Classes
A class in ECMAScript Edition 4 (per the Netscape proposal) takes a form like this:
class MyClass {
private var color : String = “red”;
public function MyClass(color : String) {
this.color = color;
}
public function sayColor() : Void {
alert(this.color);
}
}
601
The Evolution of JavaScript
23_579088 ch20.qxd 3/28/05 11:44 AM Page 601


JavaScript EditorFree JavaScript Editor     Ajax Editor


©