JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
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:
<html> <!-- Object_Data_Type_and_Value.html Copyright (c) 2008 HerongYang.com. All Rights Reserved. --> <head> <title>Object Data Type and Value</title> </head> <body> <pre> <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)); </script> </pre> </body> </html>
Run this example, you will get:
"mySite.Name" property: herongyang.com "mySite" data type: object "jsSite" data type: string
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
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 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