JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
The "Global" Object Type - The Invisible Global Container
This section provides a quick description and a tutorial example script of the 'Global' built-in object type, which is used to create a default invisible global object to hold all global properties and functions.
The "Global" object type is probably the most mysterious built-in object type. It has the following main features:
Here is a tutorial sample script showing you some of those features:
// Global_Object_Type.js // Copyright (c) 2013 HerongYang.com. All Rights Reserved. // Global() constructor is not accessible // var myGlobal = new Global(); println("\nAbout this \"this\":"); println(" Type = "+(typeof this)); println(" Instance Of Object: "+(this instanceof Object)); // "instanceof Global" is not allowed // println(" Instance Of Global: "+(this instanceof Global)); // toString() will us more println(" toString() = "+this.toString()); // Accessing a global property directly println("\nChecking NaN:"); println(" NaN: Type = "+(typeof NaN) + ", Value = "+NaN); // Accessing a global property indirectly println("\nChecking this.NaN:"); println(" this.NaN: Type = "+(typeof this.NaN) + ", Value = "+this.NaN); // Testing a global function println("\nTesting eval() in two ways:"); println(" eval('7*7') = "+eval('7*7')); println(" this.eval('7*7') = "+this.eval('7*7'));
If you run this script with "jrunscript", you will get:
About this "this": Type = object Instance Of Object: true toString() = [object Global] Checking NaN: NaN: Type = number, Value = NaN Checking this.NaN: this.NaN: Type = number, Value = NaN Testing eval() in two ways: eval('7*7') = 49 this.eval('7*7') = 49
"this.toString()" proves that "this" is a "Global" object.
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
►Introduction to Built-in Object Types
Overview of Built-in Object Types
The "Object" Object Type - The Root Object Type
►The "Global" Object Type - The Invisible Global Container
Global Properties and Functions Defined in ECMAScript
Global Properties and Functions Provided by "jrunscript"
The "Function" Object Type - Functions Are Objects
The "Array" Object Type - Arrays Are Objects
The "JSON" Object Type - parse() and stringify()
The "String" Object Type - Not Equal to String Primitive Type
The "Boolean" Object Type - Wrapping Boolean Values into Objects
The "Number" Object Type - Not Equal to Number Primitive Type
The "Date" Object Type - Managing Dates and Times
The "RegExp" Object Type - Regular Expression Patterns
The "Error" Object Type - Runtime Exceptions
The "Math" Object Type - The Math Container
W3C's Document Object Model (DOM) Specifications