Main Page

Built-in objects

Method
Description
setUTCSeconds(
seconds
)
Sets the seconds of the UTC date time.
getMilliseconds()
Returns the milliseconds of the date time. Note that
this does not refer to the milliseconds since January 1,
1970, but rather the number of milliseconds in the cur-
rent time, such as 4:55:34.20, where 20 is the number
of milliseconds of the time.
getUTCMilliseconds ()
Returns the milliseconds of the UTC date time.
setMilliseconds (
milliseconds
)
Sets the milliseconds of the date time.
setUTCMilliseconds (
millseconds
)
Sets the milliseconds of the UTC date time.
Built-in objects
ECMA-262 defines a
built-in object
as “any object supplied by an ECMAScript implementation, indepen-
dent of the host environment, which is present at the start of the execution of an ECMAScript program.”
This means the developer does not need to explicitly instantiate a built-in object; it is already instanti-
ated. Only two built-in objects are defined by ECMA-262:
Global
and
Math
(which are also both native
objects because by definition, every built-in object is a native object).
The Global object
The
Global
object is the most unique in ECMAScript because, for all intents and purposes, it doesn’t
exist. If you try typing the following line, you get an error:
var pointer = Global;
The error would say that
Global
is not an object, but didn’t I just say that it is an object? Yes. The
main concept to understand is this: In ECMAScript no standalone functions exist; all functions must
be methods of some object to actually exist. So functions covered earlier in this book such as
isNaN()
,
isFinite()
,
parseInt()
, and
parseFloat()
only look like they are standalone functions. In reality,
they are all methods of the
Global
object. But these are not the only methods for the
Global
object.
The
encodeURI()
and
encodeURIComponent()
methods are used to encode URIs (Uniform Resource
Identifiers) to be passed to the browser. To be valid, a URI cannot contain certain characters, such as
spaces. These methods help to encode the URIs so that a browser can still accept and understand them,
replacing all invalid characters with a special UTF-8 encoding.
The
encodeURI()
method is designed to work on an entire URI (for instance,
http://www.wrox.com/
illegal value.htm)
, whereas
encodeURIComponent()
is designed to work solely on a segment of a
URI (such as
illegal value.htm
from the previous URI). The main difference between the two meth-
ods is that
encodeURI()
does not encode special characters that are part of a URI such as the colon, for-
ward slash, question mark, and pound sign;
encodeURIComponent()
encodes every non-standard
character it finds. For example:
var sUri = “http://www.wrox.com/illegal value.htm#start”;
alert(encodeURI(sUri));
alert(encodeURIComponent(sUri));
81
Object Basics
06_579088 ch03.qxd 3/28/05 11:36 AM Page 81


JavaScript EditorFree JavaScript Editor     Ajax Editor


©

Bitcoin Gambling Site