What Is an Object?

This section provides a quick description of what is an object in JavaScript and some interesting features on creating and using objects. A tutorial example is also provided.

What Is an Object? - An object is an instance of a special data type called "Object" or any "prototype" data type.

JavaScript supports objects with some interesting features:

To show you some of these feature, I wrote this simple tutorial example to create an object of "Object" data type, and add a new property on this new object:

<!-- Object_Data_Type_and_Value.html
   Copyright (c) 2008 HerongYang.com. All Rights Reserved.
<title>Object Data Type and Value</title>
<script type="text/javascript">

   // Assigning a primitive value to a variable
   var jsSite = "mozilla.org";

   // Creating an object and assigning it to a variable
   var mySite = new Object();
   // Adding a new property to one object
   mySite.name = "herongyang.com";
   // Retrieving the value of object property
   document.writeln('"mySite.name" property: '+mySite.name); 

   // Checking the data type of mySite
   document.writeln('"mySite" data type: '+(typeof mySite)); 

   // Checking the data type of jsSite
   document.writeln('"jsSite" data type: '+(typeof jsSite)); 

Run this example, you will get:

"mySite.Name" property: herongyang.com
"mySite" data type: object
"jsSite" data type: string

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

Introduction to Objects

What Is an Object?

 Objects of "Object" Data Type

 Adding and Deleting Object Own Properties

 Adding and Deleting Object Own Methods

 Using "this" Keyword to Represent Current Object

 Object Literals of the "Object" Type

 Objects and Associate Arrays

 Objects with Indexed Properties

 Differences between "Object" and "Array"

 Using "Array" Objects as "Object" Objects

 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

 W3C's Document Object Model (DOM) Specifications

 AJAX (Asynchronous JavaScript And XML)


 Full Version in PDF/EPUB