Section 24.90. Global: the global object


24.90. Global: the global object

ECMAScript v1: Object Global

24.90.1. Synopsis

 this 

24.90.2. Global Properties

The global object is not a class, so the following global properties have individual reference entries under their own names. That is, you can find details on the undefined property listed under the name undefined, not under Global.undefined. Note that all top-level variables are also properties of the global object:


Infinity

A numeric value that represents positive infinity.


java

A JavaPackage that represents the java.* package hierarchy


NaN

The not-a-number value.


Packages

The root JavaPackage object.


undefined

The undefined value.

24.90.3. Global Functions

The global object is an object, not a class. The global functions listed here are not methods of any object, and their reference entries appear under the function name. For example, you'll find details on the parseInt( ) function under parseInt( ), not Global.parseInt( ):


decodeURI( )

Decodes a string escaped with encodeURI( ).


decodeURIComponent( )

Decodes a string escaped with encodeURIComponent( ).


encodeURI

Encodes a URI by escaping certain characters.


encodeURIComponent

Encodes a URI component by escaping certain characters.


escape( )

Encodes a string by replacing certain characters with escape sequences.


eval( )

Evaluates a string of JavaScript code and returns the result.


getClass( )

Returns the JavaClass of a JavaObject


isFinite( )

Tests whether a value is a finite number.


isNaN( )

Tests whether a value is the not-a-number value.


parseFloat( )

Parses a number from a string.


parseInt( )

Parses an integer from a string.


unescape( )

Decodes a string encoded with escape( ).

24.90.4. Global Objects

In addition to the global properties and functions listed earlier, the global object also defines properties that refer to all the other predefined JavaScript objects. All these properties are constructor functions that define classes except for Math, which is a reference to an object that is not a constructor:


Array

The Array( ) constructor.


Boolean

The Boolean( ) constructor.


Date

The Date( ) constructor.


Error

The Error( ) constructor.


EvalError

The EvalError( ) constructor.


Function

The Function( ) constructor.


Math

A reference to an object that defines mathematical functions.


Number

The Number( ) constructor.


Object

The Object( ) constructor.


RangeError

The RangeError( ) constructor.


ReferenceError

The ReferenceError( ) constructor.


RegExp

The RegExp( ) constructor.


String

The String( ) constructor.


SyntaxError

The SyntaxError( ) constructor.


TypeError

The TypeError( ) constructor.


URIError

The URIError( ) constructor.

24.90.5. Description

The global object is a predefined object that serves as a placeholder for the global properties and functions of JavaScript. All other predefined objects, functions, and properties are accessible through the global object. The global object is not a property of any other object, so it does not have a name. (The title of this reference page was chosen simply for organizational convenience and does not indicate that the global object is named "Global"). In top-level JavaScript code, you can refer to the global object with the keyword this. It is rarely necessary to refer to the global object in this way, however, because the global object serves as the top of the scope chain, which means that unqualified variable and function names are looked up as properties of the object. When JavaScript code refers to the parseInt( ) function, for example, it is referring to the parseInt property of the global object. The fact that the global object is the top of the scope chain also means that all variables declared in top-level JavaScript code become properties of the global object.

The global object is simply an object, not a class. There is no Global( ) constructor, and there is no way to instantiate a new global object.

When JavaScript is embedded in a particular environment, the global object is usually given additional properties that are specific to that environment. In fact, the type of the global object is not specified by the ECMAScript standard, and an implementation or embedding of JavaScript may use an object of any type as the global object, as long as the object defines the basic properties and functions listed here. For example, in JavaScript implementations that allow the scripting of Java via LiveConnect or related technologies, the global object is given the java and Packages properties and the getClass( ) method listed here. And in client-side JavaScript, the global object is a Window object and represents the web browser window within which the JavaScript code is running.

24.90.6. Example

In core JavaScript, none of the predefined properties of the global object are enumerable, so you can list all implicitly and explicitly declared global variables with a for/in loop like this:

 var variables = "" for(var name in this)     variables += name + "\n"; 

24.90.7. See Also

 Window in Part IV ; Chapter 4 




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net