ECMA-262 Core: JavaScript Object Data Type



Navigation Aids -- This Page     Navigation Aids -- This Topic     Navigation Aids -- This Site








Introduction And Review

The topic of JS objects is covered from many perspectives:

Our page entitled "JavaScript Data" will describe how JS data types interplay with the following topics:



Reference Types (also called Composite Data Types)

The Object data type is a member of the reference type group. This group also contains the Array data type and the Function data type. Sometimes all three types, Array, Function and Object are referred to as "Object types" in a generic context.

At our site, we sometimes refer to the reference data types as "composite data types". The reference data types have some unique characteristics when compared to there cousins, the primitive data types.



Types of Data Representative of the Object Data Type

A JS object may hold any type of data. An object may hold both primitive and/or composite data. The data members of an object are called properties. Function members are called methods.



Accessing Members of an Object

Properties are accessed by placing a period between the property name and the object name. Here the period represents the dot operator. Methods are accessed in the same manner, however the method requires the parentheses operator following the method name to include any argument(s) required by the method.



Creating Objects

The JS practitioner has two methods available for creating a Object type data structure.

  1. The Object Class Constructor var myObject = new Object( );// the constructor is used to instantiate an object myObject.fname = "Fritz" myObject.lname = "Fry" myObject.add1 = "12345 S. Street" myObject.city = "Town" myObject.state = "CA" myObject.zip = "null"
  2. Object Literal var myObject = {
    fname: "Fritz",
    lname: "Fry",
    add1: "12345 S. Street",
    city: "Town",
    state: "CA",
    zip: null
    }
    // the unique syntax of the object literal will type the variable as an Object

Our page entitled "User Defined Class in JavaScript" demonstrates the creation of all member types appropriate of a custom made object.



Determining Object Data Type

The data type is fairly obvious when using the Object class constructor. But when the data is created via a literal statement, then determining the data type is less obvious for the JS interpreter.

When using a literal, the Object type is distinguished from other types using a dynamic or weak typing method. The method involves interrogating the value token of the defining literal. The Object literal is distinguished from all other types by a special syntax of the defining literal. The Object literal consists of a comma separated list of property name/value pairs. Each name is suffixed with a colon, which is immediately followed with the value associated with the property. The entire set of property/value pairs are enclosed by a set of curly braces.



Object Class and Class Members

Once our object of the Object type is created, this same object has access to the members of the Object class type.



Top            

Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson